@Test public void testCreateCoordinatorStream() { SystemAdmin admin = Mockito.spy(systemAdmin()); StreamSpec spec = StreamSpec.createCoordinatorStreamSpec("testCoordinatorStream", "testSystem"); admin.createStream(spec); admin.validateStream(spec); Mockito.verify(admin).createStream(Mockito.any()); }
@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(expected = StreamValidationException.class) public void testValidateStreamDoesNotExist() { StreamSpec spec = new StreamSpec("testId", "testStreamNameExist", "testSystem", 8); systemAdmin().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 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)); }
@Test public void testGetOffsetsAfter() { SystemStreamPartition ssp1 = new SystemStreamPartition(SYSTEM(), TOPIC(), new Partition(0)); SystemStreamPartition ssp2 = new SystemStreamPartition(SYSTEM(), TOPIC(), new Partition(1)); Map<SystemStreamPartition, String> offsets = new HashMap<>(); offsets.put(ssp1, "1"); offsets.put(ssp2, "2"); offsets = systemAdmin().getOffsetsAfter(offsets); Assert.assertEquals("2", offsets.get(ssp1)); Assert.assertEquals("3", offsets.get(ssp2)); }
@Test public void testClearStream() { StreamSpec spec = new StreamSpec("testId", "testStreamClear", "testSystem", 8); KafkaSystemAdmin admin = systemAdmin(); String topicName = spec.getPhysicalName(); assertTrue("createStream should return true if the stream does not exist and then is created.", admin.createStream(spec)); // validate topic exists assertTrue(admin.clearStream(spec)); // validate that topic was removed DescribeTopicsResult dtr = admin.adminClient.describeTopics(ImmutableSet.of(topicName)); try { TopicDescription td = dtr.all().get().get(topicName); Assert.fail("topic " + topicName + " should've been removed. td=" + td); } catch (Exception e) { if (e.getCause() instanceof org.apache.kafka.common.errors.UnknownTopicOrPartitionException) { // expected } else { Assert.fail("topic " + topicName + " should've been removed. Expected UnknownTopicOrPartitionException."); } } } }
StreamSpec spec = new StreamSpec("id", topicName, SYSTEM(), defaultPartitionCount, config); KafkaSystemAdmin kafkaAdmin = systemAdmin(); KafkaStreamSpec kafkaSpec = kafkaAdmin.toKafkaSpec(spec);