public static GlobalStreamId getGlobalStreamId(String streamId, String componentId) { if (componentId == null) { return new GlobalStreamId(streamId, DEFAULT_STREAM_ID); } return new GlobalStreamId(streamId, componentId); }
/** * Get the global stream id for this input stream. * @return the GlobalStreamId for this input stream. */ public synchronized GlobalStreamId gsid() { if (gsid == null) { gsid = new GlobalStreamId(fromComponent, id); } return gsid; }
protected IdStreamSpec(String component, String stream) { _id = new GlobalStreamId(component, stream); }
public GlobalStreamId deepCopy() { return new GlobalStreamId(this); }
@Override public GlobalStreamId transform(Object key) { if (key instanceof List) { List l = (List) key; if (l.size() > 1) { return new GlobalStreamId((String) l.get(0), (String) l.get(1)); } } return new GlobalStreamId("", key.toString()); } }
private static GlobalStreamId toGlobalStreamId(List list) { return new GlobalStreamId((String) list.get(0), (String) list.get(1)); }
private void markBatchGroups(String component, Map<String, String> batchGroups) { for (Map.Entry<String, String> entry : batchGroups.entrySet()) { batchIds.put(new GlobalStreamId(component, entry.getKey()), entry.getValue()); } }
@Override public GlobalStreamId getSourceGlobalStreamId() { return new GlobalStreamId("s1", "default"); } };
@Override public GlobalStreamId getSourceGlobalStreamId() { return new GlobalStreamId(getSourceComponent(), streamId); }
private BoltDeclarer grouping(String componentId, String streamId, Grouping grouping) { commons.get(_boltId).put_to_inputs(new GlobalStreamId(componentId, streamId), grouping); return this; }
List<GlobalStreamId> getBoltSubscriptionStreams(String id) { List<GlobalStreamId> ret = new ArrayList<>(); Component c = bolts.get(id); for (InputDeclaration d : c.declarations) { ret.add(new GlobalStreamId(d.getComponent(), d.getStream())); } return ret; }
public OutputStream remap(String origId, Map<GlobalStreamId, GlobalStreamId> remappedStreams) { GlobalStreamId remapped = remappedStreams.get(new GlobalStreamId(origId, id)); return new OutputStream(remapped.get_streamId(), rate, areKeysSkewed); }
private TopologyContext getTopologyContext() { TopologyContext context = Mockito.mock(TopologyContext.class); Map<GlobalStreamId, Grouping> sources = Collections.singletonMap( new GlobalStreamId("s1", "default"), null ); Mockito.when(context.getThisSources()).thenReturn(sources); return context; }
private Tuple getTuple(String streamId, final Fields fields, Values values, String srcComponent) { return new TupleImpl(getContext(fields), values, srcComponent, 1, streamId) { @Override public GlobalStreamId getSourceGlobalStreamId() { return new GlobalStreamId("s1", "default"); } }; }
private List<Tuple> getMockTuples(int count) { List<Tuple> mockTuples = new ArrayList<>(); for (long i = 0; i < count; i++) { Tuple mockTuple = Mockito.mock(Tuple.class); Mockito.when(mockTuple.getLongByField("msgid")).thenReturn(i); Mockito.when(mockTuple.getSourceTask()).thenReturn(1); Mockito.when(mockTuple.getSourceGlobalStreamId()).thenReturn(new GlobalStreamId("a", "s")); mockTuples.add(mockTuple); } return mockTuples; } }
@Test public void testSpoutToBolt() throws Exception { Stream<Tuple> stream = streamBuilder.newStream(newSpout(Utils.DEFAULT_STREAM_ID)); stream.to(newBolt()); StormTopology topology = streamBuilder.build(); assertEquals(1, topology.get_spouts_size()); assertEquals(1, topology.get_bolts_size()); String spoutId = topology.get_spouts().keySet().iterator().next(); Map<GlobalStreamId, Grouping> expected = new HashMap<>(); expected.put(new GlobalStreamId(spoutId, "default"), Grouping.shuffle(new NullStruct())); assertEquals(expected, topology.get_bolts().values().iterator().next().get_common().get_inputs()); }
@Test public void testEmptyState() throws IOException { TmpPath tmp_dir = new TmpPath(); String dir = tmp_dir.getPath(); LocalState ls = new LocalState(dir, true); GlobalStreamId gs_a = new GlobalStreamId("a", "a"); FileOutputStream data = FileUtils.openOutputStream(new File(dir, "12345")); FileOutputStream version = FileUtils.openOutputStream(new File(dir, "12345.version")); Assert.assertNull(ls.get("c")); ls.put("a", gs_a); Assert.assertEquals(gs_a, ls.get("a")); } }
@Test public void testDeserialize_readingFromGzip() throws Exception { GlobalStreamId id = new GlobalStreamId("first", "second"); byte[] serialized = new GzipThriftSerializationDelegate().serialize(id); GlobalStreamId id2 = testDelegate.deserialize(serialized, GlobalStreamId.class); assertEquals(id2.get_componentId(), id.get_componentId()); assertEquals(id2.get_streamId(), id.get_streamId()); }
@Test public void testDeserialize_readingFromGzipBridge() throws Exception { GlobalStreamId id = new GlobalStreamId("first", "second"); byte[] serialized = new GzipBridgeThriftSerializationDelegate().serialize(id); GlobalStreamId id2 = testDelegate.deserialize(serialized, GlobalStreamId.class); assertEquals(id2.get_componentId(), id.get_componentId()); assertEquals(id2.get_streamId(), id.get_streamId()); }
@Test public void testDeserialize_readingFromDefault() throws Exception { GlobalStreamId id = new GlobalStreamId("A", "B"); byte[] serialized = new ThriftSerializationDelegate().serialize(id); GlobalStreamId id2 = testDelegate.deserialize(serialized, GlobalStreamId.class); assertEquals(id2.get_componentId(), id.get_componentId()); assertEquals(id2.get_streamId(), id.get_streamId()); } }