Search in sources :

Example 6 with ScanParams

use of redis.clients.jedis.ScanParams in project apex-malhar by apache.

the class RedisInputOperatorTest method testRecoveryAndIdempotency.

@Test
public void testRecoveryAndIdempotency() throws Exception {
    this.operatorStore = new RedisStore();
    this.testStore = new RedisStore();
    testStore.connect();
    ScanParams params = new ScanParams();
    params.count(1);
    testStore.put("test_abc", "789");
    testStore.put("test_def", "456");
    testStore.put("test_ghi", "123");
    RedisKeyValueInputOperator operator = new RedisKeyValueInputOperator();
    operator.setWindowDataManager(new FSWindowDataManager());
    operator.setStore(operatorStore);
    operator.setScanCount(1);
    Attribute.AttributeMap attributeMap = new Attribute.AttributeMap.DefaultAttributeMap();
    CollectorTestSink<Object> sink = new CollectorTestSink<Object>();
    operator.outputPort.setSink(sink);
    OperatorContext context = mockOperatorContext(1, attributeMap);
    try {
        operator.setup(context);
        operator.beginWindow(1);
        operator.emitTuples();
        operator.endWindow();
        int numberOfMessagesInWindow1 = sink.collectedTuples.size();
        sink.collectedTuples.clear();
        operator.beginWindow(2);
        operator.emitTuples();
        operator.endWindow();
        int numberOfMessagesInWindow2 = sink.collectedTuples.size();
        sink.collectedTuples.clear();
        // failure and then re-deployment of operator
        // Re-instantiating to reset values
        operator = new RedisKeyValueInputOperator();
        operator.setWindowDataManager(new FSWindowDataManager());
        operator.setStore(operatorStore);
        operator.setScanCount(1);
        operator.outputPort.setSink(sink);
        operator.setup(context);
        Assert.assertEquals("largest recovery window", 2, operator.getWindowDataManager().getLargestCompletedWindow());
        operator.beginWindow(1);
        operator.emitTuples();
        operator.emitTuples();
        operator.endWindow();
        Assert.assertEquals("num of messages in window 1", numberOfMessagesInWindow1, sink.collectedTuples.size());
        sink.collectedTuples.clear();
        operator.beginWindow(2);
        operator.emitTuples();
        operator.endWindow();
        Assert.assertEquals("num of messages in window 2", numberOfMessagesInWindow2, sink.collectedTuples.size());
    } finally {
        for (Object e : sink.collectedTuples) {
            KeyValPair<String, String> entry = (KeyValPair<String, String>) e;
            testStore.remove(entry.getKey());
        }
        sink.collectedTuples.clear();
        operator.getWindowDataManager().committed(5);
        operator.teardown();
    }
}
Also used : Attribute(com.datatorrent.api.Attribute) FSWindowDataManager(org.apache.apex.malhar.lib.wal.FSWindowDataManager) ScanParams(redis.clients.jedis.ScanParams) OperatorContextTestHelper.mockOperatorContext(org.apache.apex.malhar.lib.helper.OperatorContextTestHelper.mockOperatorContext) OperatorContext(com.datatorrent.api.Context.OperatorContext) KeyValPair(org.apache.apex.malhar.lib.util.KeyValPair) CollectorTestSink(org.apache.apex.malhar.lib.testbench.CollectorTestSink) Test(org.junit.Test)

Example 7 with ScanParams

use of redis.clients.jedis.ScanParams in project apex-malhar by apache.

the class AbstractRedisInputOperator method setup.

@Override
public void setup(OperatorContext context) {
    super.setup(context);
    sleepTimeMillis = context.getValue(context.SPIN_MILLIS);
    getWindowDataManager().setup(context);
    this.context = context;
    scanOffset = 0;
    scanComplete = false;
    scanParameters = new ScanParams();
    scanParameters.count(scanCount);
    // For the 1st window after checkpoint, windowID - 1 would not have recovery
    // offset stored in windowDataManager
    // But recoveryOffset is non-transient, so will be recovered with
    // checkPointing
    // Offset recovery from idempotency storage can be skipped in this case
    scanOffset = recoveryState.scanOffsetAtBeginWindow;
    skipOffsetRecovery = true;
}
Also used : ScanParams(redis.clients.jedis.ScanParams)

Example 8 with ScanParams

use of redis.clients.jedis.ScanParams in project xian by happyyangyuan.

the class CacheScanUnit method execute.

@Override
public UnitResponse execute(UnitRequest msg) {
    String pattern = msg.getArgMap().get("pattern").toString();
    int count = msg.get("count", Integer.class, THRESHOLD_VALUE);
    String cursor = msg.getArgMap().get("cursor").toString();
    CacheConfigBean cacheConfigBean = msg.get("cacheConfig", CacheConfigBean.class);
    try {
        JSONObject jsonObject = Redis.call(cacheConfigBean, jedis -> {
            JSONObject _jsonObject = new JSONObject();
            ScanParams params = new ScanParams().match(pattern).count(count);
            ScanResult<String> scans = jedis.scan(cursor, params);
            // 如果服务器向客户端返回 0 的游标时则表示迭代结束
            _jsonObject.put("cursor", scans.getStringCursor());
            _jsonObject.put("result", scans.getResult());
            return _jsonObject;
        });
        return UnitResponse.success(jsonObject);
    } catch (Exception e) {
        return UnitResponse.exception(e);
    }
}
Also used : CacheConfigBean(info.xiancloud.core.support.cache.CacheConfigBean) JSONObject(com.alibaba.fastjson.JSONObject) ScanParams(redis.clients.jedis.ScanParams)

Example 9 with ScanParams

use of redis.clients.jedis.ScanParams in project leshan by eclipse.

the class RedisSecurityStore method getAll.

@Override
public Collection<SecurityInfo> getAll() {
    try (Jedis j = pool.getResource()) {
        ScanParams params = new ScanParams().match(SEC_EP + "*").count(100);
        Collection<SecurityInfo> list = new LinkedList<>();
        String cursor = "0";
        do {
            ScanResult<byte[]> res = j.scan(cursor.getBytes(), params);
            for (byte[] key : res.getResult()) {
                byte[] element = j.get(key);
                list.add(deserialize(element));
            }
            cursor = res.getStringCursor();
        } while (!"0".equals(cursor));
        return list;
    }
}
Also used : Jedis(redis.clients.jedis.Jedis) ScanParams(redis.clients.jedis.ScanParams) SecurityInfo(org.eclipse.leshan.server.security.SecurityInfo) LinkedList(java.util.LinkedList)

Example 10 with ScanParams

use of redis.clients.jedis.ScanParams in project new-cloud by xie-summer.

the class HashesCommandsTest method hscanCount.

@Test
public void hscanCount() {
    ScanParams params = new ScanParams();
    params.count(2);
    for (int i = 0; i < 10; i++) {
        jedis.hset("foo", "a" + i, "a" + i);
    }
    ScanResult<Map.Entry<String, String>> result = jedis.hscan("foo", SCAN_POINTER_START, params);
    assertFalse(result.getResult().isEmpty());
    // binary
    params = new ScanParams();
    params.count(2);
    jedis.hset(bfoo, bbar, bcar);
    jedis.hset(bfoo, bbar1, bcar);
    jedis.hset(bfoo, bbar2, bcar);
    jedis.hset(bfoo, bbar3, bcar);
    ScanResult<Map.Entry<byte[], byte[]>> bResult = jedis.hscan(bfoo, SCAN_POINTER_START_BINARY, params);
    assertFalse(bResult.getResult().isEmpty());
}
Also used : ScanParams(redis.clients.jedis.ScanParams) Test(org.junit.Test)

Aggregations

ScanParams (redis.clients.jedis.ScanParams)31 Test (org.junit.Test)27 Tuple (redis.clients.jedis.Tuple)6 DAG (com.datatorrent.api.DAG)2 LocalMode (com.datatorrent.api.LocalMode)2 KeyValPair (org.apache.apex.malhar.lib.util.KeyValPair)2 JSONObject (com.alibaba.fastjson.JSONObject)1 Attribute (com.datatorrent.api.Attribute)1 OperatorContext (com.datatorrent.api.Context.OperatorContext)1 CacheConfigBean (info.xiancloud.core.support.cache.CacheConfigBean)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 LinkedList (java.util.LinkedList)1 OperatorContextTestHelper.mockOperatorContext (org.apache.apex.malhar.lib.helper.OperatorContextTestHelper.mockOperatorContext)1 CollectorTestSink (org.apache.apex.malhar.lib.testbench.CollectorTestSink)1 FieldInfo (org.apache.apex.malhar.lib.util.FieldInfo)1 FSWindowDataManager (org.apache.apex.malhar.lib.wal.FSWindowDataManager)1 SecurityInfo (org.eclipse.leshan.server.security.SecurityInfo)1 Jedis (redis.clients.jedis.Jedis)1