Skip to content

Commit

Permalink
Rename from only to singleton
Browse files Browse the repository at this point in the history
Signed-off-by: Robert Young <[email protected]>
  • Loading branch information
robobario committed Jul 3, 2023
1 parent 2add533 commit 95f8325
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
import static io.kroxylicious.test.tester.KroxyliciousConfigUtils.proxy;
import static io.kroxylicious.test.tester.KroxyliciousConfigUtils.withDefaultFilters;
import static io.kroxylicious.test.tester.KroxyliciousTesters.kroxyliciousTester;
import static io.strimzi.kafka.topicenc.kroxylicious.KafkaAssertions.assertOnlyRecordEquals;
import static io.strimzi.kafka.topicenc.kroxylicious.KafkaAssertions.assertSingletonRecordEquals;
import static io.strimzi.kafka.topicenc.kroxylicious.TopicEncryptionContributor.DECRYPT_FETCH;
import static io.strimzi.kafka.topicenc.kroxylicious.config.EncryptionModuleConfigurer.getConfiguration;
import static io.strimzi.kafka.topicenc.kroxylicious.config.EncryptionModuleConfigurer.mockKmsDefinition;
Expand Down Expand Up @@ -131,8 +131,8 @@ public void testFetchDecryption(Admin admin) {
createTopics(admin);
producer.send(new ProducerRecord<>(TOPIC_NAME_A, ENCRYPTED_VALUE_TOPIC_A)).get(10, TimeUnit.SECONDS);
producer.send(new ProducerRecord<>(TOPIC_NAME_B, ENCRYPTED_VALUE_TOPIC_B)).get(10, TimeUnit.SECONDS);
assertOnlyRecordEquals(proxyConsumer, TOPIC_NAME_A, UNENCRYPTED_VALUE);
assertOnlyRecordEquals(proxyConsumer, TOPIC_NAME_B, UNENCRYPTED_VALUE);
assertSingletonRecordEquals(proxyConsumer, TOPIC_NAME_A, UNENCRYPTED_VALUE);
assertSingletonRecordEquals(proxyConsumer, TOPIC_NAME_B, UNENCRYPTED_VALUE);
} catch (Exception e) {
throw new RuntimeException(e);
}
Expand All @@ -146,7 +146,7 @@ public void testTopicWithoutPolicyIsNotDecrypted(Admin admin) {
) {
createTopics(admin);
producer.send(new ProducerRecord<>(UNENCRYPTED_TOPIC, ENCRYPTED_VALUE_TOPIC_A)).get(10, TimeUnit.SECONDS);
assertOnlyRecordEquals(proxyConsumer, UNENCRYPTED_TOPIC, ENCRYPTED_VALUE_TOPIC_A);
KafkaAssertions.assertSingletonRecordEquals(proxyConsumer, UNENCRYPTED_TOPIC, ENCRYPTED_VALUE_TOPIC_A);
} catch (Exception e) {
throw new RuntimeException(e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,18 @@

public class KafkaAssertions {

public static void assertOnlyRecordEquals(Consumer<String, byte[]> kafkaClusterConsumer, String topic, byte[] expected) {
public static void assertSingletonRecordEquals(Consumer<String, byte[]> kafkaClusterConsumer, String topic, byte[] expected) {
ConsumerRecord<String, byte[]> onlyRecord = getOnlyRecord(kafkaClusterConsumer, topic);
assertArrayEquals(expected, onlyRecord.value(), "only record value in " + topic + " did not match expectation");
}

public static void assertOnlyRecordEquals(Consumer<String, byte[]> kafkaClusterConsumer, String topic, Function<byte[], String> transform, String expected) {
public static void assertSingletonRecordEquals(Consumer<String, byte[]> kafkaClusterConsumer, String topic, Function<byte[], String> transform, String expected) {
ConsumerRecord<String, byte[]> onlyRecord = getOnlyRecord(kafkaClusterConsumer, topic);
String transformed = transform.apply(onlyRecord.value());
assertEquals(expected, transformed, "only record value in " + topic + " did not match expectation");
}

public static void assertOnlyRecordEquals(Consumer<String, String> kafkaClusterConsumer, String topic, String expected) {
public static void assertSingletonRecordEquals(Consumer<String, String> kafkaClusterConsumer, String topic, String expected) {
ConsumerRecord<String, String> onlyRecord = getOnlyRecord(kafkaClusterConsumer, topic);
assertEquals(expected, onlyRecord.value(), "only record value in " + topic + " did not match expectation");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import io.kroxylicious.testing.kafka.api.KafkaCluster;
import io.kroxylicious.testing.kafka.junit5ext.KafkaClusterExtension;
import io.strimzi.kafka.topicenc.kms.KmsDefinition;
import io.strimzi.kafka.topicenc.kroxylicious.config.EncryptionModuleConfigurer;
import io.strimzi.kafka.topicenc.policy.TopicPolicy;
import org.apache.kafka.clients.admin.Admin;
import org.apache.kafka.clients.admin.NewTopic;
Expand Down Expand Up @@ -33,7 +32,7 @@
import static io.kroxylicious.test.tester.KroxyliciousConfigUtils.proxy;
import static io.kroxylicious.test.tester.KroxyliciousConfigUtils.withDefaultFilters;
import static io.kroxylicious.test.tester.KroxyliciousTesters.kroxyliciousTester;
import static io.strimzi.kafka.topicenc.kroxylicious.KafkaAssertions.assertOnlyRecordEquals;
import static io.strimzi.kafka.topicenc.kroxylicious.KafkaAssertions.assertSingletonRecordEquals;
import static io.strimzi.kafka.topicenc.kroxylicious.TopicEncryptionContributor.ENCRYPT_PRODUCE;
import static io.strimzi.kafka.topicenc.kroxylicious.config.EncryptionModuleConfigurer.getConfiguration;
import static io.strimzi.kafka.topicenc.kroxylicious.config.EncryptionModuleConfigurer.mockKmsDefinition;
Expand Down Expand Up @@ -83,8 +82,8 @@ public void testFetchDecryption(Admin admin) {
createTopics(admin);
producer.send(new ProducerRecord<>(TOPIC_NAME_A, UNENCRYPTED_VALUE)).get(10, TimeUnit.SECONDS);
producer.send(new ProducerRecord<>(TOPIC_NAME_B, UNENCRYPTED_VALUE)).get(10, TimeUnit.SECONDS);
assertOnlyRecordEquals(proxyConsumer, TOPIC_NAME_A, (s) -> decrypt(s, TOPIC_NAME_A), UNENCRYPTED_VALUE);
assertOnlyRecordEquals(proxyConsumer, TOPIC_NAME_B, (s) -> decrypt(s, TOPIC_NAME_B), UNENCRYPTED_VALUE);
KafkaAssertions.assertSingletonRecordEquals(proxyConsumer, TOPIC_NAME_A, (s) -> decrypt(s, TOPIC_NAME_A), UNENCRYPTED_VALUE);
KafkaAssertions.assertSingletonRecordEquals(proxyConsumer, TOPIC_NAME_B, (s) -> decrypt(s, TOPIC_NAME_B), UNENCRYPTED_VALUE);
} catch (Exception e) {
throw new RuntimeException(e);
}
Expand All @@ -103,7 +102,7 @@ public void testTopicWithoutPolicyIsNotEncrypted(Admin admin) {
) {
createTopics(admin);
producer.send(new ProducerRecord<>(UNENCRYPTED_TOPIC, UNENCRYPTED_VALUE)).get(10, TimeUnit.SECONDS);
assertOnlyRecordEquals(proxyConsumer, UNENCRYPTED_TOPIC, UNENCRYPTED_VALUE);
assertSingletonRecordEquals(proxyConsumer, UNENCRYPTED_TOPIC, UNENCRYPTED_VALUE);
} catch (Exception e) {
throw new RuntimeException(e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,8 @@ public void testFetchDecryption(Admin admin) {
admin.createTopics(List.of(new NewTopic(TOPIC_NAME_A, 1, (short) 1), new NewTopic(TOPIC_NAME_B, 1, (short) 1))).all().get(10, TimeUnit.SECONDS);
producer.send(new ProducerRecord<>(TOPIC_NAME_A, ENCRYPTED_VALUE_TOPIC_A)).get(10, TimeUnit.SECONDS);
producer.send(new ProducerRecord<>(TOPIC_NAME_B, ENCRYPTED_VALUE_TOPIC_B)).get(10, TimeUnit.SECONDS);
KafkaAssertions.assertOnlyRecordEquals(consumer, TOPIC_NAME_A, UNENCRYPTED_VALUE);
KafkaAssertions.assertOnlyRecordEquals(consumer, TOPIC_NAME_B, UNENCRYPTED_VALUE);
KafkaAssertions.assertSingletonRecordEquals(consumer, TOPIC_NAME_A, UNENCRYPTED_VALUE);
KafkaAssertions.assertSingletonRecordEquals(consumer, TOPIC_NAME_B, UNENCRYPTED_VALUE);
} catch (Exception e) {
throw new RuntimeException(e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
import static io.kroxylicious.test.tester.KroxyliciousConfigUtils.proxy;
import static io.kroxylicious.test.tester.KroxyliciousConfigUtils.withDefaultFilters;
import static io.kroxylicious.test.tester.KroxyliciousTesters.kroxyliciousTester;
import static io.strimzi.kafka.topicenc.kroxylicious.KafkaAssertions.assertOnlyRecordEquals;
import static io.strimzi.kafka.topicenc.kroxylicious.KafkaAssertions.assertSingletonRecordEquals;
import static io.strimzi.kafka.topicenc.kroxylicious.TopicEncryptionContributor.ENCRYPT_PRODUCE;
import static io.strimzi.kafka.topicenc.kroxylicious.config.EncryptionModuleConfigurer.getConfiguration;
import static io.strimzi.kafka.topicenc.kroxylicious.config.EncryptionModuleConfigurer.vaultKmsDefinition;
Expand Down Expand Up @@ -95,8 +95,8 @@ public void testProduceEncryption(Admin admin) {
admin.createTopics(List.of(new NewTopic(TOPIC_NAME_A, 1, (short) 1), new NewTopic(TOPIC_NAME_B, 1, (short) 1))).all().get(10, TimeUnit.SECONDS);
producer.send(new ProducerRecord<>(TOPIC_NAME_A, UNENCRYPTED_VALUE)).get(10, TimeUnit.SECONDS);
producer.send(new ProducerRecord<>(TOPIC_NAME_B, UNENCRYPTED_VALUE)).get(10, TimeUnit.SECONDS);
assertOnlyRecordEquals(consumer, TOPIC_NAME_A, (s) -> decrypt(s, TOPIC_NAME_A), UNENCRYPTED_VALUE);
assertOnlyRecordEquals(consumer, TOPIC_NAME_B, (s) -> decrypt(s, TOPIC_NAME_B), UNENCRYPTED_VALUE);
KafkaAssertions.assertSingletonRecordEquals(consumer, TOPIC_NAME_A, (s) -> decrypt(s, TOPIC_NAME_A), UNENCRYPTED_VALUE);
KafkaAssertions.assertSingletonRecordEquals(consumer, TOPIC_NAME_B, (s) -> decrypt(s, TOPIC_NAME_B), UNENCRYPTED_VALUE);
} catch (Exception e) {
throw new RuntimeException(e);
}
Expand Down

0 comments on commit 95f8325

Please sign in to comment.