Search in sources :

Example 1 with MongoDBClient

use of org.apache.storm.mongodb.common.MongoDBClient in project storm by apache.

the class MongoState method prepare.

protected void prepare() {
    Validate.notEmpty(options.url, "url can not be blank or null");
    Validate.notEmpty(options.collectionName, "collectionName can not be blank or null");
    this.mongoClient = new MongoDBClient(options.url, options.collectionName);
}
Also used : MongoDBClient(org.apache.storm.mongodb.common.MongoDBClient)

Example 2 with MongoDBClient

use of org.apache.storm.mongodb.common.MongoDBClient 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)

Example 3 with MongoDBClient

use of org.apache.storm.mongodb.common.MongoDBClient in project storm by apache.

the class AbstractMongoBolt method prepare.

@Override
public void prepare(Map stormConf, TopologyContext context, OutputCollector collector) {
    this.collector = collector;
    this.mongoClient = new MongoDBClient(url, collectionName);
}
Also used : MongoDBClient(org.apache.storm.mongodb.common.MongoDBClient)

Aggregations

MongoDBClient (org.apache.storm.mongodb.common.MongoDBClient)3 MongoState (org.apache.storm.mongodb.trident.state.MongoState)1 MongoStateUpdater (org.apache.storm.mongodb.trident.state.MongoStateUpdater)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