@Test public void testSDConfigs() { GenericSystemDescriptor mySystem = new GenericSystemDescriptor("input-system", "factory.class.name") .withSystemConfigs(ImmutableMap.of("custom-config-key", "custom-config-value")) .withDefaultStreamConfigs(ImmutableMap.of("custom-stream-config-key", "custom-stream-config-value")) .withDefaultStreamOffsetDefault(SystemStreamMetadata.OffsetType.UPCOMING); Map<String, String> generatedConfigs = mySystem.toConfig(); Map<String, String> expectedConfigs = ImmutableMap.of( "systems.input-system.samza.factory", "factory.class.name", "systems.input-system.custom-config-key", "custom-config-value", "systems.input-system.default.stream.custom-stream-config-key", "custom-stream-config-value", "systems.input-system.default.stream.samza.offset.default", "upcoming" ); assertEquals(expectedConfigs, generatedConfigs); }
@Test public void testISDObjectsWithOverrides() { GenericSystemDescriptor mySystem = new GenericSystemDescriptor("input-system", "factory.class.name") .withSystemConfigs(Collections.emptyMap()) .withDefaultStreamConfigs(Collections.emptyMap()); IntegerSerde streamSerde = new IntegerSerde(); GenericInputDescriptor<Integer> isd = mySystem.getInputDescriptor("input-stream", streamSerde); assertEquals(streamSerde, isd.getSerde()); assertFalse(isd.getTransformer().isPresent()); } }
@Test public void testISDConfigsWithOverrides() { GenericSystemDescriptor mySystem = new GenericSystemDescriptor("input-system", "factory.class.name") .withSystemConfigs(Collections.emptyMap()) .withDefaultStreamConfigs(Collections.emptyMap()); GenericInputDescriptor<Double> isd = mySystem.getInputDescriptor("input-stream", new DoubleSerde()) .withPhysicalName("physical-name") .shouldBootstrap() .isBounded() .shouldDeleteCommittedMessages() .withOffsetDefault(SystemStreamMetadata.OffsetType.OLDEST) .withPriority(12) .shouldResetOffset() .withStreamConfigs(ImmutableMap.of("custom-config-key", "custom-config-value")); Map<String, String> generatedConfigs = isd.toConfig(); Map<String, String> expectedConfigs = new HashMap<>(); expectedConfigs.put("streams.input-stream.samza.system", "input-system"); expectedConfigs.put("streams.input-stream.samza.physical.name", "physical-name"); expectedConfigs.put("streams.input-stream.samza.bootstrap", "true"); expectedConfigs.put("streams.input-stream.samza.bounded", "true"); expectedConfigs.put("streams.input-stream.samza.delete.committed.messages", "true"); expectedConfigs.put("streams.input-stream.samza.reset.offset", "true"); expectedConfigs.put("streams.input-stream.samza.offset.default", "oldest"); expectedConfigs.put("streams.input-stream.samza.priority", "12"); expectedConfigs.put("streams.input-stream.custom-config-key", "custom-config-value"); assertEquals(expectedConfigs, generatedConfigs); }
@Test public void testISDConfigsWithDefaults() { GenericSystemDescriptor mySystem = new GenericSystemDescriptor("input-system", "factory.class.name") .withSystemConfigs(Collections.emptyMap()) .withDefaultStreamConfigs(Collections.emptyMap()); DoubleSerde streamSerde = new DoubleSerde(); GenericInputDescriptor<Double> isd = mySystem.getInputDescriptor("input-stream", streamSerde); Map<String, String> generatedConfigs = isd.toConfig(); Map<String, String> expectedConfigs = ImmutableMap.of("streams.input-stream.samza.system", "input-system"); assertEquals(expectedConfigs, generatedConfigs); assertEquals(streamSerde, isd.getSerde()); assertFalse(isd.getTransformer().isPresent()); }
@Test public void testAPIUsage() { // does not assert anything, but acts as a compile-time check on expected descriptor type parameters // and validates that the method calls can be chained. GenericSystemDescriptor mySystem = new GenericSystemDescriptor("input-system", "factory.class.name") .withSystemConfigs(Collections.emptyMap()) .withDefaultStreamConfigs(Collections.emptyMap()); GenericInputDescriptor<Integer> input1 = mySystem.getInputDescriptor("input1", new IntegerSerde()); GenericOutputDescriptor<Integer> output1 = mySystem.getOutputDescriptor("output1", new IntegerSerde()); input1 .withPhysicalName("input-1") .shouldBootstrap() .withOffsetDefault(SystemStreamMetadata.OffsetType.NEWEST) .withPriority(1) .shouldResetOffset() .isBounded() .shouldDeleteCommittedMessages() .withStreamConfigs(Collections.emptyMap()); output1 .withPhysicalName("output-1") .withStreamConfigs(Collections.emptyMap()); }