Search in sources :

Example 6 with StateUpdater

use of org.apache.storm.trident.state.StateUpdater in project storm by apache.

the class TestMongoDataSourcesProvider method testMongoSink.

@SuppressWarnings("unchecked")
@Test
public void testMongoSink() {
    ISqlTridentDataSource ds = DataSourcesRegistry.constructTridentDataSource(URI.create("mongodb://127.0.0.1:27017/test"), null, null, TBL_PROPERTIES, FIELDS);
    Assert.assertNotNull(ds);
    ISqlTridentDataSource.SqlTridentConsumer consumer = ds.getConsumer();
    Assert.assertEquals(MongoStateFactory.class, consumer.getStateFactory().getClass());
    Assert.assertEquals(MongoStateUpdater.class, consumer.getStateUpdater().getClass());
    MongoState state = (MongoState) consumer.getStateFactory().makeState(Collections.emptyMap(), null, 0, 1);
    StateUpdater stateUpdater = consumer.getStateUpdater();
    MongoDBClient mongoClient = mock(MongoDBClient.class);
    Whitebox.setInternalState(state, "mongoClient", mongoClient);
    List<TridentTuple> tupleList = mockTupleList();
    for (TridentTuple t : tupleList) {
        stateUpdater.updateState(state, Collections.singletonList(t), null);
        verify(mongoClient).insert(argThat(new MongoArgMatcher(t)), eq(true));
    }
    verifyNoMoreInteractions(mongoClient);
}
Also used : MongoState(org.apache.storm.mongodb.trident.state.MongoState) ISqlTridentDataSource(org.apache.storm.sql.runtime.ISqlTridentDataSource) MongoStateUpdater(org.apache.storm.mongodb.trident.state.MongoStateUpdater) StateUpdater(org.apache.storm.trident.state.StateUpdater) MongoDBClient(org.apache.storm.mongodb.common.MongoDBClient) TridentTuple(org.apache.storm.trident.tuple.TridentTuple) Test(org.junit.Test)

Aggregations

StateUpdater (org.apache.storm.trident.state.StateUpdater)6 ISqlTridentDataSource (org.apache.storm.sql.runtime.ISqlTridentDataSource)5 TridentTuple (org.apache.storm.trident.tuple.TridentTuple)5 Test (org.junit.Test)5 RedisClusterStateUpdater (org.apache.storm.redis.trident.state.RedisClusterStateUpdater)2 RedisStateUpdater (org.apache.storm.redis.trident.state.RedisStateUpdater)2 IOException (java.io.IOException)1 Properties (java.util.Properties)1 HdfsState (org.apache.storm.hdfs.trident.HdfsState)1 HdfsFileOptions (org.apache.storm.hdfs.trident.HdfsState.HdfsFileOptions)1 MongoDBClient (org.apache.storm.mongodb.common.MongoDBClient)1 MongoState (org.apache.storm.mongodb.trident.state.MongoState)1 MongoStateUpdater (org.apache.storm.mongodb.trident.state.MongoStateUpdater)1 RedisClusterState (org.apache.storm.redis.trident.state.RedisClusterState)1 RedisState (org.apache.storm.redis.trident.state.RedisState)1 SocketState (org.apache.storm.sql.runtime.datasource.socket.trident.SocketState)1 SocketStateUpdater (org.apache.storm.sql.runtime.datasource.socket.trident.SocketStateUpdater)1 GroupedStream (org.apache.storm.trident.fluent.GroupedStream)1 IAggregatableStream (org.apache.storm.trident.fluent.IAggregatableStream)1 CombinerAggStateUpdater (org.apache.storm.trident.operation.impl.CombinerAggStateUpdater)1