@Test public void testGetTable() throws Exception { Config mockConfig = getConfig(); String tableId = "t1"; BaseTableDescriptor mockTableDescriptor = mock(BaseTableDescriptor.class); when(mockTableDescriptor.getTableId()).thenReturn(tableId); AtomicReference<TableImpl> table = new AtomicReference<>(); StreamApplicationDescriptorImpl streamAppDesc = new StreamApplicationDescriptorImpl(appDesc -> { table.set((TableImpl) appDesc.getTable(mockTableDescriptor)); }, mockConfig); assertEquals(tableId, table.get().getTableId()); }
@Test public void testEmptyChain() { StreamApplicationDescriptorImpl graphSpec = new StreamApplicationDescriptorImpl(appDesc -> { }, mock(Config.class)); OperatorImplGraph opGraph = new OperatorImplGraph(graphSpec.getOperatorSpecGraph(), context, mock(Clock.class)); assertEquals(0, opGraph.getAllInputOperators().size()); }
@Test(expected = IllegalArgumentException.class) public void testScheduledFunctionAsValueFn() { ScheduledMapFn valueFn = new ScheduledMapFn(); new StreamApplicationDescriptorImpl(appDesc -> { MessageStream<Object> inputStream = appDesc.getInputStream(testInputDescriptor); inputStream.partitionBy(m -> m.toString(), valueFn, mock(KVSerde.class), "parByKey"); }, getConfig()); }
@Test(expected = IllegalArgumentException.class) public void testWatermarkFunctionAsValueFn() { WatermarkMapFn valueFn = new WatermarkMapFn(); new StreamApplicationDescriptorImpl(appDesc -> { MessageStream<Object> inputStream = appDesc.getInputStream(testInputDescriptor); inputStream.partitionBy(m -> m.toString(), valueFn, mock(KVSerde.class), "parByKey"); }, getConfig()); }
@Test(expected = NullPointerException.class) public void testGetIntermediateStreamWithNoSerde() { Config mockConfig = getConfig(); String streamId = "streamId"; StreamApplicationDescriptorImpl streamAppDesc = new StreamApplicationDescriptorImpl(appDesc -> { }, mockConfig); IntermediateMessageStreamImpl<TestMessageEnvelope> intermediateStreamImpl = streamAppDesc.getIntermediateStream(streamId, null, false); // should throw }
@Test public void testApplicationTaskContextFactory() { ApplicationTaskContextFactory factory = mock(ApplicationTaskContextFactory.class); StreamApplication testApp = appDesc -> appDesc.withApplicationTaskContextFactory(factory); StreamApplicationDescriptorImpl appSpec = new StreamApplicationDescriptorImpl(testApp, getConfig()); assertEquals(appSpec.getApplicationTaskContextFactory(), Optional.of(factory)); }
@Test public void testConstructor() { StreamApplication mockApp = mock(StreamApplication.class); Config mockConfig = getConfig(); StreamApplicationDescriptorImpl appDesc = new StreamApplicationDescriptorImpl(mockApp, mockConfig); verify(mockApp).describe(appDesc); assertEquals(mockConfig, appDesc.getConfig()); }
@Test public void testApplicationContainerContextFactory() { ApplicationContainerContextFactory factory = mock(ApplicationContainerContextFactory.class); StreamApplication testApp = appDesc -> appDesc.withApplicationContainerContextFactory(factory); StreamApplicationDescriptorImpl appSpec = new StreamApplicationDescriptorImpl(testApp, getConfig()); assertEquals(appSpec.getApplicationContainerContextFactory(), Optional.of(factory)); }
@Test(expected = IllegalArgumentException.class) public void testWatermarkFunctionAsKeyFn() { WatermarkMapFn keyFn = new WatermarkMapFn(); new StreamApplicationDescriptorImpl(appDesc -> { MessageStream<Object> inputStream = appDesc.getInputStream(testInputDescriptor); inputStream.partitionBy(keyFn, m -> m, mock(KVSerde.class), "parByKey"); }, getConfig()); }
@Test(expected = IllegalArgumentException.class) public void testScheduledFunctionAsKeyFn() { ScheduledMapFn keyFn = new ScheduledMapFn(); new StreamApplicationDescriptorImpl(appDesc -> { MessageStream<Object> inputStream = appDesc.getInputStream(testInputDescriptor); inputStream.partitionBy(keyFn, m -> m, mock(KVSerde.class), "parByKey"); }, getConfig()); }
@Test(expected = IllegalStateException.class) public void testGetSameOutputStreamTwice() { String streamId = "test-stream-1"; GenericSystemDescriptor sd = new GenericSystemDescriptor("mockSystem", "mockSystemFactoryClass"); GenericOutputDescriptor osd1 = sd.getOutputDescriptor(streamId, mock(Serde.class)); GenericOutputDescriptor osd2 = sd.getOutputDescriptor(streamId, mock(Serde.class)); new StreamApplicationDescriptorImpl(appDesc -> { appDesc.getOutputStream(osd1); appDesc.getOutputStream(osd2); // should throw exception }, getConfig()); }
@Test(expected = IllegalStateException.class) public void testGetSameInputStreamTwice() { String streamId = "test-stream-1"; GenericSystemDescriptor sd = new GenericSystemDescriptor("mockSystem", "mockSystemFactoryClass"); GenericInputDescriptor isd1 = sd.getInputDescriptor(streamId, mock(Serde.class)); GenericInputDescriptor isd2 = sd.getInputDescriptor(streamId, mock(Serde.class)); new StreamApplicationDescriptorImpl(appDesc -> { appDesc.getInputStream(isd1); // should throw exception appDesc.getInputStream(isd2); }, getConfig()); }
@Test public void testCopy() { StreamApplicationDescriptorImpl streamAppDesc = new StreamApplicationDescriptorImpl(appDesc -> { MessageStream inputStream = appDesc.getInputStream(testInputDescriptor); inputStream.partitionBy(m -> m.toString(), m -> m, mock(KVSerde.class), testRepartitionedStreamName); }, getConfig()); OperatorSpecGraph specGraph = streamAppDesc.getOperatorSpecGraph(); OperatorSpecGraph clonedGraph = specGraph.clone(); OperatorSpecTestUtils.assertClonedGraph(specGraph, clonedGraph); }
@Test(expected = IllegalStateException.class) public void testSetDefaultSystemDescriptorAfterGettingOutputStream() { String streamId = "test-stream-1"; GenericSystemDescriptor sd = new GenericSystemDescriptor("mockSystem", "mockSystemFactoryClass"); GenericOutputDescriptor osd = sd.getOutputDescriptor(streamId, mock(Serde.class)); new StreamApplicationDescriptorImpl(appDesc -> { appDesc.getOutputStream(osd); appDesc.withDefaultSystem(sd); // should throw exception }, getConfig()); }
@Test(expected = IllegalStateException.class) public void testSetDefaultSystemDescriptorAfterGettingInputStream() { String streamId = "test-stream-1"; GenericSystemDescriptor sd = new GenericSystemDescriptor("mockSystem", "mockSystemFactoryClass"); GenericInputDescriptor isd = sd.getInputDescriptor(streamId, mock(Serde.class)); new StreamApplicationDescriptorImpl(appDesc -> { appDesc.getInputStream(isd); appDesc.withDefaultSystem(sd); // should throw exception }, getConfig()); }
@Test public void testGetNextOpIdIncrementsId() { HashMap<String, String> configMap = new HashMap<>(); configMap.put(JobConfig.JOB_NAME(), "jobName"); configMap.put(JobConfig.JOB_ID(), "1234"); Config config = new MapConfig(configMap); StreamApplicationDescriptorImpl streamAppDesc = new StreamApplicationDescriptorImpl(appDesc -> { }, config); assertEquals("jobName-1234-merge-0", streamAppDesc.getNextOpId(OpCode.MERGE, null)); assertEquals("jobName-1234-join-customName", streamAppDesc.getNextOpId(OpCode.JOIN, "customName")); assertEquals("jobName-1234-map-2", streamAppDesc.getNextOpId(OpCode.MAP, null)); }
@Test(expected = IllegalArgumentException.class) public void testGetInputStreamWithNullSerde() { GenericSystemDescriptor sd = new GenericSystemDescriptor("mockSystem", "mockSystemFactoryClass"); GenericInputDescriptor isd = sd.getInputDescriptor("mockStreamId", null); new StreamApplicationDescriptorImpl(appDesc -> { appDesc.getInputStream(isd); }, getConfig()); }
@Test(expected = IllegalArgumentException.class) public void testGetOutputStreamWithNullSerde() { String streamId = "test-stream-1"; GenericSystemDescriptor sd = new GenericSystemDescriptor("mockSystem", "mockSystemFactoryClass"); GenericOutputDescriptor osd = sd.getOutputDescriptor(streamId, null); new StreamApplicationDescriptorImpl(appDesc -> { appDesc.getOutputStream(osd); }, getConfig()); }
@Test public void testGetInputStreamWithRelaxedTypes() { String streamId = "test-stream-1"; GenericSystemDescriptor sd = new GenericSystemDescriptor("mockSystem", "mockSystemFactoryClass"); GenericInputDescriptor isd = sd.getInputDescriptor(streamId, mock(Serde.class)); StreamApplicationDescriptorImpl streamAppDesc = new StreamApplicationDescriptorImpl(appDesc -> { appDesc.getInputStream(isd); }, getConfig()); InputOperatorSpec inputOpSpec = streamAppDesc.getInputOperators().get(streamId); assertEquals(OpCode.INPUT, inputOpSpec.getOpCode()); assertEquals(streamId, inputOpSpec.getStreamId()); assertEquals(isd, streamAppDesc.getInputDescriptors().get(streamId)); }
@Test public void testGetIntermediateStreamWithDefaultSystemDescriptor() { Config mockConfig = getConfig(); String streamId = "streamId"; StreamApplicationDescriptorImpl streamAppDesc = new StreamApplicationDescriptorImpl(appDesc -> { }, mockConfig); GenericSystemDescriptor sd = new GenericSystemDescriptor("mock-system", "mock-system-factory"); streamAppDesc.withDefaultSystem(sd); IntermediateMessageStreamImpl<TestMessageEnvelope> intermediateStreamImpl = streamAppDesc.getIntermediateStream(streamId, mock(Serde.class), false); assertEquals(streamAppDesc.getInputOperators().get(streamId), intermediateStreamImpl.getOperatorSpec()); assertEquals(streamAppDesc.getOutputStreams().get(streamId), intermediateStreamImpl.getOutputStream()); assertEquals(streamId, intermediateStreamImpl.getStreamId()); }