@Test(expected = StreamValidationException.class) public void testValidateStreamDoesNotExist() { StreamSpec spec = new StreamSpec("testId", "testStreamNameExist", "testSystem", 8); systemAdmin().validateStream(spec); }
public void testCreateChangelogStreamHelp(final String topic) { final int PARTITIONS = 12; final int REP_FACTOR = 2; Map<String, String> map = new HashMap<>(); map.put(JobConfig.JOB_DEFAULT_SYSTEM(), SYSTEM()); map.put(String.format("stores.%s.changelog", "fakeStore"), topic); map.put(String.format("stores.%s.changelog.replication.factor", "fakeStore"), String.valueOf(REP_FACTOR)); map.put(String.format("stores.%s.changelog.kafka.segment.bytes", "fakeStore"), "139"); KafkaSystemAdmin admin = Mockito.spy(createSystemAdmin(SYSTEM(), map)); StreamSpec spec = StreamSpec.createChangeLogStreamSpec(topic, SYSTEM(), PARTITIONS); Mockito.doAnswer(invocationOnMock -> { StreamSpec internalSpec = (StreamSpec) invocationOnMock.callRealMethod(); assertTrue(internalSpec instanceof KafkaStreamSpec); // KafkaStreamSpec is used to carry replication factor assertTrue(internalSpec.isChangeLogStream()); assertEquals(SYSTEM(), internalSpec.getSystemName()); assertEquals(topic, internalSpec.getPhysicalName()); assertEquals(REP_FACTOR, ((KafkaStreamSpec) internalSpec).getReplicationFactor()); assertEquals(PARTITIONS, internalSpec.getPartitionCount()); assertEquals("139", ((KafkaStreamSpec) internalSpec).getProperties().getProperty("segment.bytes")); assertEquals("compact", ((KafkaStreamSpec) internalSpec).getProperties().getProperty("cleanup.policy")); return internalSpec; }).when(admin).toKafkaSpec(Mockito.any()); admin.createStream(spec); admin.validateStream(spec); }
@Test public void testCreateCoordinatorStreamWithSpecialCharsInTopicName() { final String STREAM = "test.coordinator_test.Stream"; Map<String, String> map = new HashMap<>(); map.put("job.coordinator.segment.bytes", "123"); map.put("job.coordinator.cleanup.policy", "compact"); int coordReplicatonFactor = 2; map.put(org.apache.samza.config.KafkaConfig.JOB_COORDINATOR_REPLICATION_FACTOR(), String.valueOf(coordReplicatonFactor)); KafkaSystemAdmin admin = Mockito.spy(createSystemAdmin(SYSTEM(), map)); StreamSpec spec = StreamSpec.createCoordinatorStreamSpec(STREAM, SYSTEM()); Mockito.doAnswer(invocationOnMock -> { StreamSpec internalSpec = (StreamSpec) invocationOnMock.callRealMethod(); assertTrue(internalSpec instanceof KafkaStreamSpec); // KafkaStreamSpec is used to carry replication factor assertTrue(internalSpec.isCoordinatorStream()); assertEquals(SYSTEM(), internalSpec.getSystemName()); assertEquals(STREAM, internalSpec.getPhysicalName()); assertEquals(1, internalSpec.getPartitionCount()); Assert.assertEquals(coordReplicatonFactor, ((KafkaStreamSpec) internalSpec).getReplicationFactor()); Assert.assertEquals("123", ((KafkaStreamSpec) internalSpec).getProperties().getProperty("segment.bytes")); // cleanup policy is overridden in the KafkaAdmin Assert.assertEquals("compact", ((KafkaStreamSpec) internalSpec).getProperties().getProperty("cleanup.policy")); return internalSpec; }).when(admin).toKafkaSpec(Mockito.any()); admin.createStream(spec); admin.validateStream(spec); }
@Test(expected = StreamValidationException.class) public void testValidateStreamWrongName() { StreamSpec spec1 = new StreamSpec("testId", "testStreamName1", "testSystem", 8); StreamSpec spec2 = new StreamSpec("testId", "testStreamName2", "testSystem", 8); assertTrue("createStream should return true if the stream does not exist and then is created.", systemAdmin().createStream(spec1)); systemAdmin().validateStream(spec2); }
@Test(expected = StreamValidationException.class) public void testValidateStreamWrongPartitionCount() { StreamSpec spec1 = new StreamSpec("testId", "testStreamPartition", "testSystem", 8); StreamSpec spec2 = new StreamSpec("testId", "testStreamPartition", "testSystem", 4); assertTrue("createStream should return true if the stream does not exist and then is created.", systemAdmin().createStream(spec1)); systemAdmin().validateStream(spec2); }
@Test public void testCreateStream() { StreamSpec spec = new StreamSpec("testId", "testStream", "testSystem", 8); KafkaSystemAdmin admin = systemAdmin(); assertTrue("createStream should return true if the stream does not exist and then is created.", admin.createStream(spec)); admin.validateStream(spec); assertFalse("createStream should return false if the stream already exists.", systemAdmin().createStream(spec)); }