This HTTP web API manages and accesses recording and replaying resources from a remote repository. Resources are organized as MockItem instances, each corresponding to a MockCategoryType enum.
- Agent Recording
- Assigns version numbers to configuration files.
- Saves entry points and dependent instances implementing MockItem.
- Agent Replaying
- Reads configuration files by version number prior to replaying.
- Handles requests, performs diffs, and retrieves mock results as responses.
- Scheduled Replaying
- Uses MainEntry (extending MockItem) as replay trigger sources.
- Provides diff response sources saved from agent’s replay.
- Recording Storage (MongoDB): Default persistence for AREX’s agent recording. Collections are time-managed with TTL index expiration.
- Replaying Cache (Redis): Default cache for AREX’s replaying.
The base interface MockItem, defined in arex.storage.model.mocker, is structured as follows:
public interface MockItem {
String getReplayId();
void setReplayId(String replayId);
String getRecordId();
void setRecordId(String recordId);
/**
* millis from utc format without timezone
*/
void setCreateTime(long createTime);
}
-
Identifiers:
replayId
andrecordId
are generated by AREX's Agent. -
MainEntry
Interface: Defined inarex.storage.model.mocker
,MainEntry
extendsMockItem
and includes methods for accessing request details, category type, format, and more.public interface MainEntry extends MockItem { /** * @return utc format without timezone */ long getCreateTime(); /** * The request's content encoded by base64 * */ String getRequest(); /** * @return the mock category type value from MockCategoryType * @see MockCategoryType */ @JsonIgnore int getCategoryType(); /** * How to serialize the request's body to target ,default using application/json * * @return application/json or others */ default String getFormat() { return null; } /** * @return default http post */ default String getMethod() { return "POST"; } default Map<String, String> getRequestHeaders() { return null; } default String getPath() { return null; } }
-
Configuring Remote Storage: Modify the
localhost
default value inresources/META-INF/application.properties
for Redis and MongoDB connections. Example:arex.storage.cache.redis.host=redis://10.3.2.42:6379/ arex.mongo.uri=mongodb://arex:[email protected]:27017/arex_storage_db
-
Extending Providers: Implement your own providers using Java's
SPI
mechanism. TheCacheProvider
interface is defined as:public interface CacheProvider { /** * put the value with expired seconds * @param key the key for value * @param expiredSeconds the expired seconds * @param value bytes of the object * @return true if success,others false */ boolean put(byte[] key, long expiredSeconds, byte[] value); /** * Get the value of a key * * @param key the bytes of key * @return null when key does not exist. */ byte[] get(byte[] key); /** * Increment integer value of the key by on * * @param key the key * @return The value of the key after increment */ long incrValue(byte[] key); /** * Decrement the integer value of a key by one. * * @param key the key * @return the value of key after decrement */ long decrValue(byte[] key); /** * Delete value specified by the key * * @param key the bytes of key * @return True if key is removed. */ boolean remove(byte[] key); }
- Code: Apache-2.0