Search in sources :

Example 1 with RedisState

use of org.apache.storm.redis.trident.state.RedisState in project storm by apache.

the class TestRedisDataSourcesProvider method testRedisSink.

@SuppressWarnings("unchecked")
@Test
public void testRedisSink() {
    ISqlTridentDataSource ds = DataSourcesRegistry.constructTridentDataSource(URI.create("redis://:foobared@localhost:6380/2"), null, null, TBL_PROPERTIES, FIELDS);
    Assert.assertNotNull(ds);
    ISqlTridentDataSource.SqlTridentConsumer consumer = ds.getConsumer();
    Assert.assertEquals(RedisState.Factory.class, consumer.getStateFactory().getClass());
    Assert.assertEquals(RedisStateUpdater.class, consumer.getStateUpdater().getClass());
    RedisState state = (RedisState) consumer.getStateFactory().makeState(Collections.emptyMap(), null, 0, 1);
    StateUpdater stateUpdater = consumer.getStateUpdater();
    JedisPool mockJedisPool = mock(JedisPool.class);
    Jedis mockJedis = mock(Jedis.class);
    Pipeline mockPipeline = mock(Pipeline.class);
    Whitebox.setInternalState(state, "jedisPool", mockJedisPool);
    when(mockJedisPool.getResource()).thenReturn(mockJedis);
    when(mockJedis.pipelined()).thenReturn(mockPipeline);
    List<TridentTuple> tupleList = mockTupleList();
    stateUpdater.updateState(state, tupleList, null);
    for (TridentTuple t : tupleList) {
        // PK goes to the key
        String id = String.valueOf(t.getValueByField("ID"));
        String serializedValue = new String(SERIALIZER.write(t.getValues(), null).array());
        verify(mockPipeline).hset(eq(ADDITIONAL_KEY), eq(id), eq(serializedValue));
    }
    verify(mockPipeline).sync();
    verify(mockJedis).close();
}
Also used : Jedis(redis.clients.jedis.Jedis) RedisState(org.apache.storm.redis.trident.state.RedisState) ISqlTridentDataSource(org.apache.storm.sql.runtime.ISqlTridentDataSource) JedisPool(redis.clients.jedis.JedisPool) StateUpdater(org.apache.storm.trident.state.StateUpdater) RedisStateUpdater(org.apache.storm.redis.trident.state.RedisStateUpdater) RedisClusterStateUpdater(org.apache.storm.redis.trident.state.RedisClusterStateUpdater) Pipeline(redis.clients.jedis.Pipeline) TridentTuple(org.apache.storm.trident.tuple.TridentTuple) Test(org.junit.Test)

Aggregations

RedisClusterStateUpdater (org.apache.storm.redis.trident.state.RedisClusterStateUpdater)1 RedisState (org.apache.storm.redis.trident.state.RedisState)1 RedisStateUpdater (org.apache.storm.redis.trident.state.RedisStateUpdater)1 ISqlTridentDataSource (org.apache.storm.sql.runtime.ISqlTridentDataSource)1 StateUpdater (org.apache.storm.trident.state.StateUpdater)1 TridentTuple (org.apache.storm.trident.tuple.TridentTuple)1 Test (org.junit.Test)1 Jedis (redis.clients.jedis.Jedis)1 JedisPool (redis.clients.jedis.JedisPool)1 Pipeline (redis.clients.jedis.Pipeline)1