use of org.apache.storm.trident.tuple.TridentTuple in project storm by apache.
the class TestMongoDataSourcesProvider method mockTupleList.
private static List<TridentTuple> mockTupleList() {
List<TridentTuple> tupleList = new ArrayList<>();
TridentTuple t0 = mock(TridentTuple.class);
TridentTuple t1 = mock(TridentTuple.class);
doReturn(1).when(t0).get(0);
doReturn(2).when(t1).get(0);
doReturn(Lists.<Object>newArrayList(1, "2")).when(t0).getValues();
doReturn(Lists.<Object>newArrayList(2, "3")).when(t1).getValues();
tupleList.add(t0);
tupleList.add(t1);
return tupleList;
}
use of org.apache.storm.trident.tuple.TridentTuple 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");
}
}
use of org.apache.storm.trident.tuple.TridentTuple in project storm by apache.
the class TestRedisDataSourcesProvider method mockTupleList.
private static List<TridentTuple> mockTupleList() {
List<TridentTuple> tupleList = new ArrayList<>();
TridentTuple t0 = mock(TridentTuple.class);
TridentTuple t1 = mock(TridentTuple.class);
when(t0.getValueByField("ID")).thenReturn(1);
when(t0.getValueByField("val")).thenReturn("2");
doReturn(Lists.<Object>newArrayList(1, "2")).when(t0).getValues();
when(t1.getValueByField("ID")).thenReturn(2);
when(t1.getValueByField("val")).thenReturn("3");
doReturn(Lists.<Object>newArrayList(2, "3")).when(t1).getValues();
tupleList.add(t0);
tupleList.add(t1);
return tupleList;
}
use of org.apache.storm.trident.tuple.TridentTuple in project storm by apache.
the class SocketStateUpdater method updateState.
@Override
public void updateState(SocketState state, List<TridentTuple> tuples, TridentCollector collector) {
try {
for (TridentTuple tuple : tuples) {
byte[] array = outputSerializer.write(tuple.getValues(), null).array();
String data = new String(array);
state.write(data + "\n");
}
state.flush();
} catch (IOException e) {
LOG.error("Error while updating state.", e);
collector.reportError(e);
throw new RuntimeException("Error while updating state.", e);
}
}
use of org.apache.storm.trident.tuple.TridentTuple in project storm by apache.
the class DruidBeamState method update.
public List<E> update(List<TridentTuple> tuples, TridentCollector collector) {
List<E> events = new ArrayList<>(tuples.size());
for (TridentTuple tuple : tuples) {
events.add(druidEventMapper.getEvent(tuple));
}
LOG.info("Sending [{}] events", events.size());
scala.collection.immutable.List<E> scalaList = scala.collection.JavaConversions.collectionAsScalaIterable(events).toList();
Collection<Future<SendResult>> futureList = scala.collection.JavaConversions.asJavaCollection(beam.sendAll(scalaList));
List<E> discardedEvents = new ArrayList<>();
int index = 0;
for (Future<SendResult> future : futureList) {
try {
SendResult result = Await.result(future);
if (!result.sent()) {
discardedEvents.add(events.get(index));
}
} catch (Exception e) {
LOG.error("Failed in writing messages to Druid", e);
}
index++;
}
return discardedEvents;
}
Aggregations