public TopicWithSchema createTopic(String group, String topic) { Topic created = topic(group, topic) .withRetentionTime(1000) .withDescription("Test topic") .build(); return createTopic(created); }
public TopicWithSchema createTopic(String group, String topic) { Topic created = topic(group, topic) .withRetentionTime(1000) .withDescription("Test topic") .build(); return createTopic(created); }
public boolean topicExists(String topicName, String kafkaClusterName) { Topic topic = topic(topicName).build(); return kafkaNamesMapper.toKafkaTopics(topic) .allMatch(kafkaTopic -> zkClients.get(kafkaClusterName).topicExists(kafkaTopic.name().asString()) && !isMarkedForDeletion(kafkaClusterName, kafkaTopic)); }
@Test public void shouldThrowExceptionWhenMessageCouldNotBeUnwrappedByAnySchema() { // given Topic topic = topic("group", "topic").build(); byte[] doesNotMatchAnySchema = "{}".getBytes(); // when catchException(messageContentWrapper).unwrapAvro(doesNotMatchAnySchema, topic); // then assertThat(caughtException() instanceof SchemaMissingException).isTrue(); assertThat(metrics.errorsForAnySchemaVersion().getCount()).isEqualTo(1); assertThat(metrics.errorsForAnyOnlineSchemaVersion().getCount()).isEqualTo(1); }
public boolean topicExists(String topicName, String kafkaClusterName) { Topic topic = topic(topicName).build(); return kafkaNamesMapper.toKafkaTopics(topic) .allMatch(kafkaTopic -> zkClients.get(kafkaClusterName).topicExists(kafkaTopic.name().asString()) && !isMarkedForDeletion(kafkaClusterName, kafkaTopic)); }
@Test public void shouldUseEveryoneConfirmProducerForTopicWithAckAll() { //given Topic topic = topic("group.all").withAck(Topic.Ack.ALL).build(); CachedTopic cachedTopic = new CachedTopic(topic, hermesMetrics, kafkaNamesMapper.toKafkaTopics(topic)); //when producer.send(MESSAGE, cachedTopic, new DoNothing()); //then List<ProducerRecord<byte[], byte[]>> records = everyoneConfirmProducer.history(); assertThat(records.size()).isEqualTo(1); assertThat(records.get(0).topic()).isEqualTo("ns_group.all"); }
@Test public void shouldNotResetPrimitiveFields() { // given Topic topic = topic("group.topic").withTrackingEnabled(true).build(); PatchData patch = patchData().set("schemaVersionAwareSerializationEnabled", true).build(); // when Topic patched = Patch.apply(topic, patch); // then assertThat(patched.isTrackingEnabled()).isTrue(); assertThat(patched.isSchemaVersionAwareSerializationEnabled()).isTrue(); } }
private void createTopic(String topicName, KafkaZkClient kafkaZkClient) { Topic topic = topic(topicName).build(); kafkaNamesMapper.toKafkaTopics(topic).forEach(kafkaTopic -> { AdminZkClient adminZkClient = new AdminZkClient(kafkaZkClient); adminZkClient.createTopic(kafkaTopic.name().asString(), DEFAULT_PARTITIONS, DEFAULT_REPLICATION_FACTOR, new Properties(), RackAwareMode.Enforced$.MODULE$); waitAtMost(adjust(Duration.ONE_MINUTE)).until(() -> { kafkaZkClient.topicExists(kafkaTopic.name().asString()); } ); }); }
private void createTopic(String topicName, KafkaZkClient kafkaZkClient) { Topic topic = topic(topicName).build(); kafkaNamesMapper.toKafkaTopics(topic).forEach(kafkaTopic -> { AdminZkClient adminZkClient = new AdminZkClient(kafkaZkClient); adminZkClient.createTopic(kafkaTopic.name().asString(), DEFAULT_PARTITIONS, DEFAULT_REPLICATION_FACTOR, new Properties(), RackAwareMode.Enforced$.MODULE$); waitAtMost(adjust(Duration.ONE_MINUTE)).until(() -> { kafkaZkClient.topicExists(kafkaTopic.name().asString()); } ); }); }
@Test public void shouldCreateRepositoryThenCloseAndRestore() { //given Message message = generateMessage(); String qualifiedName = "groupName.topic"; Topic topic = topic(qualifiedName).build(); String baseDir = Files.createTempDir().getAbsolutePath(); File file = new File(baseDir, "messages.dat"); messageRepository = new ChronicleMapMessageRepository(file, ENTRIES, AVERAGE_MESSAGE_SIZE); //when messageRepository.save(message, topic); //then messageRepository.close(); //when messageRepository = new ChronicleMapMessageRepository(file, ENTRIES, AVERAGE_MESSAGE_SIZE); //then assertThat(messageRepository.findAll()).contains(new BackupMessage(message.getId(), message.getData(), message.getTimestamp(), qualifiedName)); }
@Test public void shouldSaveFindAndDeleteMessage() { //given String qualifiedName = "groupName.topic"; Message message = generateMessage(); String id = message.getId(); byte[] messageContent = message.getData(); long timestamp = message.getTimestamp(); Topic topic = topic(qualifiedName).build(); //when messageRepository.save(message, topic); //then assertThat(messageRepository.findAll()).contains(new BackupMessage(id, messageContent, timestamp, qualifiedName)); //when messageRepository.delete(id); //then assertThat(messageRepository.findAll()).isEmpty(); }
@Test public void shouldSaveMultipleTimesFindAndDeleteMessage() { //given String messageContent = "hello world"; Message message1 = generateMessage(messageContent); Message message2 = generateMessage(messageContent); String id1 = message1.getId(); String id2 = message2.getId(); String qualifiedName = "groupName.topic"; Topic topic = topic(qualifiedName).build(); //when messageRepository.save(message1, topic); messageRepository.save(message2, topic); messageRepository.save(message1, topic); messageRepository.save(message2, topic); //then assertThat(messageRepository.findAll()).contains(new BackupMessage(id1, messageContent.getBytes(), message1.getTimestamp(), qualifiedName)); //when messageRepository.delete(id1); //then assertThat(messageRepository.findAll()).hasSize(1); assertThat(messageRepository.findAll()).contains(new BackupMessage(id2, messageContent.getBytes(), message2.getTimestamp(), qualifiedName)); }
@Test public void shouldConvertToJsonWithoutMetadata() throws IOException { // given Topic topic = topic("group.topic").build(); AvroUser avroUser = new AvroUser("Bob", 18, "blue"); Message source = message() .withData(avroUser.asBytes()) .withSchema(new CompiledSchema<>(avroUser.getSchema(), SchemaVersion.valueOf(0))) .withExternalMetadata(of()) .build(); AvroToJsonMessageConverter converter = new AvroToJsonMessageConverter(); // when Message target = converter.convert(source, topic); // then assertThatJson(new String(target.getData())).isEqualTo("{\"name\": \"Bob\", \"age\": 18, \"favoriteColor\": \"blue\"}"); }
private SubscriptionName createSubscription(SubscriptionName subscriptionName) { Subscription subscription = subscription(subscriptionName).build(); Group group = Group.from(subscription.getTopicName().getGroupName()); if (!groupRepository.groupExists(group.getGroupName())) { groupRepository.createGroup(group); } if (!topicRepository.topicExists(subscription.getTopicName())) { topicRepository.createTopic(topic(subscription.getTopicName()).build()); } subscriptionRepository.createSubscription(subscription); await().atMost(adjust(ONE_SECOND)).until( () -> { subscriptionRepository.subscriptionExists(subscription.getTopicName(), subscription.getName()); subscriptionsCaches.forEach(subscriptionsCache -> subscriptionsCache.listActiveSubscriptionNames().contains(subscriptionName)); } ); return subscription.getQualifiedName(); }