@Test(expected = IllegalArgumentException.class) public void testGetStreamStreamIdInvalid() { Config config = buildStreamConfig(STREAM_ID_INVALID, StreamConfig.SYSTEM(), TEST_SYSTEM); StreamUtil.getStreamSpec(STREAM_ID_INVALID, new StreamConfig(config)); }
@Test(expected = IllegalArgumentException.class) public void testGetStreamStreamIdEmpty() { Config config = buildStreamConfig("", StreamConfig.SYSTEM(), TEST_SYSTEM); StreamUtil.getStreamSpec("", new StreamConfig(config)); }
@Test public void testStreamConfigOverridesWithSystemDefaults() { Config config = addConfigs(buildStreamConfig(STREAM_ID, StreamConfig.PHYSICAL_NAME(), TEST_PHYSICAL_NAME, StreamConfig.SYSTEM(), TEST_SYSTEM, "segment.bytes", "5309"), String.format("systems.%s.default.stream.replication.factor", TEST_SYSTEM), "4", // System default property String.format("systems.%s.default.stream.segment.bytest", TEST_SYSTEM), "867" ); StreamSpec spec = StreamUtil.getStreamSpec(STREAM_ID, new StreamConfig(config)); Map<String, String> properties = spec.getConfig(); assertEquals(3, properties.size()); assertEquals("4", properties.get("replication.factor")); // Uses system default assertEquals("5309", properties.get("segment.bytes")); // Overrides system default }
@Test(expected = IllegalArgumentException.class) public void testGetStreamStreamIdNull() { Config config = buildStreamConfig(null, StreamConfig.SYSTEM(), TEST_SYSTEM); StreamUtil.getStreamSpec(null, new StreamConfig(config)); }
@Test(expected = IllegalArgumentException.class) public void testGetStreamSystemNameArgEmpty() { Config config = buildStreamConfig(STREAM_ID, StreamConfig.PHYSICAL_NAME(), TEST_PHYSICAL_NAME, StreamConfig.SYSTEM(), ""); StreamSpec spec = StreamUtil.getStreamSpec(STREAM_ID, new StreamConfig(config)); }
@Test(expected = IllegalArgumentException.class) public void testGetStreamSystemNameArgInvalid() { Config config = buildStreamConfig(STREAM_ID, StreamConfig.PHYSICAL_NAME(), TEST_PHYSICAL_NAME, StreamConfig.SYSTEM(), TEST_SYSTEM_INVALID); StreamUtil.getStreamSpec(STREAM_ID, new StreamConfig(config)); }
@Test(expected = IllegalArgumentException.class) public void testGetStreamSystemNameArgNull() { Config config = buildStreamConfig(STREAM_ID, StreamConfig.PHYSICAL_NAME(), TEST_PHYSICAL_NAME, StreamConfig.SYSTEM(), null); StreamUtil.getStreamSpec(STREAM_ID, new StreamConfig(config)); }
@Test public void testGetStreamWithoutPhysicalNameInConfig() { Config config = buildStreamConfig(STREAM_ID, StreamConfig.SYSTEM(), TEST_SYSTEM); StreamSpec spec = StreamUtil.getStreamSpec(STREAM_ID, new StreamConfig(config)); assertEquals(STREAM_ID, spec.getPhysicalName()); }
@Test public void testGetStreamWithSystemAtStreamScopeInConfig() { Config config = buildStreamConfig(STREAM_ID, StreamConfig.PHYSICAL_NAME(), TEST_PHYSICAL_NAME, StreamConfig.SYSTEM(), TEST_SYSTEM); StreamSpec spec = StreamUtil.getStreamSpec(STREAM_ID, new StreamConfig(config)); assertEquals(TEST_SYSTEM, spec.getSystemName()); }
@Test public void testGetStreamWithPhysicalNameInConfig() { Config config = buildStreamConfig(STREAM_ID, StreamConfig.PHYSICAL_NAME(), TEST_PHYSICAL_NAME, StreamConfig.SYSTEM(), TEST_SYSTEM); StreamSpec spec = StreamUtil.getStreamSpec(STREAM_ID, new StreamConfig(config)); assertEquals(TEST_PHYSICAL_NAME, spec.getPhysicalName()); }
@Test public void testGetStreamPhysicalNameArgSpecialCharacters() { Config config = buildStreamConfig(STREAM_ID, StreamConfig.PHYSICAL_NAME(), TEST_PHYSICAL_NAME_SPECIAL_CHARS, StreamConfig.SYSTEM(), TEST_SYSTEM); StreamSpec spec = StreamUtil.getStreamSpec(STREAM_ID, new StreamConfig(config)); assertEquals(TEST_PHYSICAL_NAME_SPECIAL_CHARS, spec.getPhysicalName()); }
@Test public void testGetStreamPhysicalNameArgNull() { Config config = buildStreamConfig(STREAM_ID, StreamConfig.PHYSICAL_NAME(), null, StreamConfig.SYSTEM(), TEST_SYSTEM); StreamSpec spec = StreamUtil.getStreamSpec(STREAM_ID, new StreamConfig(config)); assertNull(spec.getPhysicalName()); }
@Test public void testContainsSamzaPropertyFromStreamId() { StreamConfig config = buildConfig("key1", "value1", buildProp(STREAM1_STREAM_ID, "samza.key2"), "value2", buildProp(STREAM1_STREAM_ID, StreamConfig.SYSTEM()), STREAM1_SYSTEM, buildProp(STREAM1_STREAM_ID, StreamConfig.PHYSICAL_NAME()), STREAM1_PHYSICAL_NAME); assertTrue(config.containsSamzaProperty(SYSTEM_STREAM_1, "samza.key2")); }
@Test public void testGetStreamWithSystemAtBothScopesInConfig() { Config config = addConfigs(buildStreamConfig(STREAM_ID, StreamConfig.PHYSICAL_NAME(), TEST_PHYSICAL_NAME, StreamConfig.SYSTEM(), TEST_SYSTEM), JobConfig.JOB_DEFAULT_SYSTEM(), TEST_DEFAULT_SYSTEM); StreamSpec spec = StreamUtil.getStreamSpec(STREAM_ID, new StreamConfig(config)); assertEquals(TEST_SYSTEM, spec.getSystemName()); }
@Test public void testGetSerdeStreamsFromStreamId() { StreamConfig config = buildConfig( buildProp(STREAM1_STREAM_ID, StreamConfig.SYSTEM()), STREAM1_SYSTEM, buildProp(STREAM1_STREAM_ID, StreamConfig.PHYSICAL_NAME()), STREAM1_PHYSICAL_NAME, buildProp(STREAM1_STREAM_ID, StreamConfig.KEY_SERDE()), "value1", buildProp(STREAM2_STREAM_ID, StreamConfig.SYSTEM()), STREAM2_SYSTEM, buildProp(STREAM2_STREAM_ID, StreamConfig.PHYSICAL_NAME()), STREAM2_PHYSICAL_NAME, buildProp(STREAM2_STREAM_ID, StreamConfig.MSG_SERDE()), "value2", "key3", "value3"); assertEquals(1, config.getSerdeStreams(STREAM1_SYSTEM).size()); assertEquals(1, config.getSerdeStreams(STREAM2_SYSTEM).size()); assertEquals("value1", config.getStreamKeySerde(SYSTEM_STREAM_1).get()); assertEquals("value2", config.getStreamMsgSerde(SYSTEM_STREAM_2).get()); }
@Test public void testContainsSamzaPropertyFromSystemStreamAndStreamId() { StreamConfig config = buildConfig("key1", "value1", buildProp(SYSTEM_STREAM_1, "samza.key2"), "value2", buildProp(STREAM1_STREAM_ID, "samza.key2"), "value2OVERRIDE", buildProp(STREAM1_STREAM_ID, StreamConfig.SYSTEM()), STREAM1_SYSTEM, buildProp(STREAM1_STREAM_ID, StreamConfig.PHYSICAL_NAME()), STREAM1_PHYSICAL_NAME); assertTrue(config.containsSamzaProperty(SYSTEM_STREAM_1, "samza.key2")); }
@Test public void testGetSamzaPropertyFromSystemStreamAndStreamId() { StreamConfig config = buildConfig("key1", "value1", buildProp(SYSTEM_STREAM_1, "samza.key2"), "value2", buildProp(STREAM1_STREAM_ID, "samza.key2"), "value2OVERRIDE", buildProp(STREAM1_STREAM_ID, StreamConfig.SYSTEM()), STREAM1_SYSTEM, buildProp(STREAM1_STREAM_ID, StreamConfig.PHYSICAL_NAME()), STREAM1_PHYSICAL_NAME); assertEquals("value2OVERRIDE", config.getSamzaProperty(SYSTEM_STREAM_1, "samza.key2")); }
@Test public void testGetStreamPhysicalNameArgSimple() { Config config = buildStreamConfig(STREAM_ID, StreamConfig.PHYSICAL_NAME(), TEST_PHYSICAL_NAME2, // This should be ignored because of the explicit arg StreamConfig.SYSTEM(), TEST_SYSTEM); StreamSpec spec = StreamUtil.getStreamSpec(STREAM_ID, new StreamConfig(config)); assertEquals(STREAM_ID, spec.getId()); assertEquals(TEST_PHYSICAL_NAME2, spec.getPhysicalName()); assertEquals(TEST_SYSTEM, spec.getSystemName()); }
@Test public void testGetStreamSystemNameArgValid() { Config config = buildStreamConfig(STREAM_ID, StreamConfig.PHYSICAL_NAME(), TEST_PHYSICAL_NAME, // This should be ignored because of the explicit arg StreamConfig.SYSTEM(), TEST_SYSTEM); // This too StreamSpec spec = StreamUtil.getStreamSpec(STREAM_ID, new StreamConfig(config)); assertEquals(STREAM_ID, spec.getId()); assertEquals(TEST_PHYSICAL_NAME, spec.getPhysicalName()); assertEquals(TEST_SYSTEM, spec.getSystemName()); }
@Test public void testGetSamzaPropertyFromStreamId() { StreamConfig config = buildConfig("key1", "value1", buildProp(STREAM1_STREAM_ID, "samza.key2"), "value2", buildProp(STREAM1_STREAM_ID, StreamConfig.SYSTEM()), STREAM1_SYSTEM, buildProp(STREAM1_STREAM_ID, StreamConfig.BROADCAST()), "true", buildProp(STREAM1_STREAM_ID, StreamConfig.PHYSICAL_NAME()), STREAM1_PHYSICAL_NAME); assertEquals("value2", config.getSamzaProperty(SYSTEM_STREAM_1, "samza.key2")); assertEquals("true", config.getSamzaProperty(SYSTEM_STREAM_1, "samza.broadcast")); }