Skip to content

A dedicated service for storing and managing recorded and replayed data in AREX.

Notifications You must be signed in to change notification settings

arextest/arex-storage

Repository files navigation

Arex Icon AREX Storage Service

Introduction

Overview

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.

Key Functions

  1. Agent Recording
    • Assigns version numbers to configuration files.
    • Saves entry points and dependent instances implementing MockItem.
  2. Agent Replaying
    • Reads configuration files by version number prior to replaying.
    • Handles requests, performs diffs, and retrieves mock results as responses.
  3. Scheduled Replaying
    • Uses MainEntry (extending MockItem) as replay trigger sources.
    • Provides diff response sources saved from agent’s replay.

Persistence and Caching

  • 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.

MockItem Interface

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);
  }

Additional Details

  • Identifiers: replayId and recordId are generated by AREX's Agent.

  • MainEntry Interface: Defined in arex.storage.model.mocker, MainEntry extends MockItem 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;
          }
      }

Getting Started

  1. Configuring Remote Storage: Modify the localhost default value in resources/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:iLoveArex@10.3.2.42:27017/arex_storage_db
    
  2. Extending Providers: Implement your own providers using Java's SPI mechanism. The CacheProvider 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);    
    }

License