Search in sources :

Example 1 with SocketState

use of org.apache.storm.sql.runtime.datasource.socket.trident.SocketState in project storm by apache.

the class TestSocketDataSourceProvider method testSocketSink.

@Test
public void testSocketSink() throws IOException {
    ISqlTridentDataSource ds = DataSourcesRegistry.constructTridentDataSource(URI.create("socket://localhost:8888"), null, null, new Properties(), FIELDS);
    Assert.assertNotNull(ds);
    ISqlTridentDataSource.SqlTridentConsumer consumer = ds.getConsumer();
    Assert.assertEquals(SocketState.Factory.class, consumer.getStateFactory().getClass());
    Assert.assertEquals(SocketStateUpdater.class, consumer.getStateUpdater().getClass());
    // makeState() fails on creating State so we just mock SocketState anyway
    SocketState mockState = mock(SocketState.class);
    StateUpdater stateUpdater = consumer.getStateUpdater();
    List<TridentTuple> tupleList = mockTupleList();
    stateUpdater.updateState(mockState, tupleList, null);
    for (TridentTuple t : tupleList) {
        String serializedValue = new String(SERIALIZER.write(t.getValues(), null).array());
        verify(mockState).write(serializedValue + "\n");
    }
}
Also used : ISqlTridentDataSource(org.apache.storm.sql.runtime.ISqlTridentDataSource) Properties(java.util.Properties) SocketState(org.apache.storm.sql.runtime.datasource.socket.trident.SocketState) StateUpdater(org.apache.storm.trident.state.StateUpdater) SocketStateUpdater(org.apache.storm.sql.runtime.datasource.socket.trident.SocketStateUpdater) TridentTuple(org.apache.storm.trident.tuple.TridentTuple) Test(org.junit.Test)

Aggregations

Properties (java.util.Properties)1 ISqlTridentDataSource (org.apache.storm.sql.runtime.ISqlTridentDataSource)1 SocketState (org.apache.storm.sql.runtime.datasource.socket.trident.SocketState)1 SocketStateUpdater (org.apache.storm.sql.runtime.datasource.socket.trident.SocketStateUpdater)1 StateUpdater (org.apache.storm.trident.state.StateUpdater)1 TridentTuple (org.apache.storm.trident.tuple.TridentTuple)1 Test (org.junit.Test)1