Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions foreign/java/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -234,5 +234,6 @@ Before opening a pull request:

1. **Format code:** `./gradlew spotlessApply`
2. **Validate build:** `./gradlew check`
3. **Use AssertJ for assertions:** Tests should use [AssertJ](https://assertj.github.io/doc/) (`assertThat(...)`) instead of JUnit assertions.

This ensures code style compliance and that all tests and checkstyle validations pass.
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,8 @@
import java.util.HashMap;
import java.util.Map;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;

class IggyStreamConfigTest {

Expand All @@ -38,16 +36,16 @@ void testValidConfiguration() {
StreamConfig streamConfig = new StreamConfig("test_table_REALTIME", props);
IggyStreamConfig config = new IggyStreamConfig(streamConfig);

assertEquals("localhost", config.getHost());
assertEquals(8090, config.getPort());
assertEquals("iggy", config.getUsername());
assertEquals("iggy", config.getPassword());
assertEquals("analytics", config.getStreamId());
assertEquals("events", config.getTopicId());
assertEquals("test-consumer-group", config.getConsumerGroup());
assertEquals(100, config.getPollBatchSize());
assertEquals(4, config.getConnectionPoolSize());
assertFalse(config.isEnableTls());
assertThat(config.getHost()).isEqualTo("localhost");
assertThat(config.getPort()).isEqualTo(8090);
assertThat(config.getUsername()).isEqualTo("iggy");
assertThat(config.getPassword()).isEqualTo("iggy");
assertThat(config.getStreamId()).isEqualTo("analytics");
assertThat(config.getTopicId()).isEqualTo("events");
assertThat(config.getConsumerGroup()).isEqualTo("test-consumer-group");
assertThat(config.getPollBatchSize()).isEqualTo(100);
assertThat(config.getConnectionPoolSize()).isEqualTo(4);
assertThat(config.isEnableTls()).isFalse();
}

@Test
Expand All @@ -63,12 +61,12 @@ void testCustomConfiguration() {
StreamConfig streamConfig = new StreamConfig("test_table_REALTIME", props);
IggyStreamConfig config = new IggyStreamConfig(streamConfig);

assertEquals(9090, config.getPort());
assertEquals("custom-user", config.getUsername());
assertEquals("custom-pass", config.getPassword());
assertEquals(500, config.getPollBatchSize());
assertEquals(8, config.getConnectionPoolSize());
assertTrue(config.isEnableTls());
assertThat(config.getPort()).isEqualTo(9090);
assertThat(config.getUsername()).isEqualTo("custom-user");
assertThat(config.getPassword()).isEqualTo("custom-pass");
assertThat(config.getPollBatchSize()).isEqualTo(500);
assertThat(config.getConnectionPoolSize()).isEqualTo(8);
assertThat(config.isEnableTls()).isTrue();
}

@Test
Expand All @@ -78,10 +76,9 @@ void testMissingHostThrowsException() {

StreamConfig streamConfig = new StreamConfig("test_table_REALTIME", props);

IllegalArgumentException exception =
assertThrows(IllegalArgumentException.class, () -> new IggyStreamConfig(streamConfig));

assertTrue(exception.getMessage().contains("host"));
assertThatThrownBy(() -> new IggyStreamConfig(streamConfig))
.isInstanceOf(IllegalArgumentException.class)
.hasMessageContaining("host");
}

@Test
Expand All @@ -91,10 +88,9 @@ void testMissingStreamIdThrowsException() {

StreamConfig streamConfig = new StreamConfig("test_table_REALTIME", props);

IllegalArgumentException exception =
assertThrows(IllegalArgumentException.class, () -> new IggyStreamConfig(streamConfig));

assertTrue(exception.getMessage().contains("stream ID"));
assertThatThrownBy(() -> new IggyStreamConfig(streamConfig))
.isInstanceOf(IllegalArgumentException.class)
.hasMessageContaining("stream ID");
}

@Test
Expand All @@ -104,10 +100,9 @@ void testMissingTopicIdThrowsException() {

StreamConfig streamConfig = new StreamConfig("test_table_REALTIME", props);

IllegalArgumentException exception =
assertThrows(IllegalArgumentException.class, () -> new IggyStreamConfig(streamConfig));

assertTrue(exception.getMessage().contains("topic ID"));
assertThatThrownBy(() -> new IggyStreamConfig(streamConfig))
.isInstanceOf(IllegalArgumentException.class)
.hasMessageContaining("topic ID");
}

@Test
Expand All @@ -117,10 +112,9 @@ void testMissingConsumerGroupThrowsException() {

StreamConfig streamConfig = new StreamConfig("test_table_REALTIME", props);

IllegalArgumentException exception =
assertThrows(IllegalArgumentException.class, () -> new IggyStreamConfig(streamConfig));

assertTrue(exception.getMessage().contains("consumer group"));
assertThatThrownBy(() -> new IggyStreamConfig(streamConfig))
.isInstanceOf(IllegalArgumentException.class)
.hasMessageContaining("consumer group");
}

@Test
Expand All @@ -129,7 +123,7 @@ void testServerAddress() {
StreamConfig streamConfig = new StreamConfig("test_table_REALTIME", props);
IggyStreamConfig config = new IggyStreamConfig(streamConfig);

assertEquals("localhost:8090", config.getServerAddress());
assertThat(config.getServerAddress()).isEqualTo("localhost:8090");
}

@Test
Expand All @@ -138,7 +132,7 @@ void testTableNameWithType() {
StreamConfig streamConfig = new StreamConfig("events_REALTIME", props);
IggyStreamConfig config = new IggyStreamConfig(streamConfig);

assertEquals("events_REALTIME", config.getTableNameWithType());
assertThat(config.getTableNameWithType()).isEqualTo("events_REALTIME");
}

@Test
Expand All @@ -148,11 +142,12 @@ void testToString() {
IggyStreamConfig config = new IggyStreamConfig(streamConfig);

String str = config.toString();
assertTrue(str.contains("localhost"));
assertTrue(str.contains("8090"));
assertTrue(str.contains("analytics"));
assertTrue(str.contains("events"));
assertTrue(str.contains("test-consumer-group"));
assertThat(str)
.contains("localhost")
.contains("8090")
.contains("analytics")
.contains("events")
.contains("test-consumer-group");
}

@Test
Expand All @@ -164,8 +159,8 @@ void testNumericStreamAndTopicIds() {
StreamConfig streamConfig = new StreamConfig("test_table_REALTIME", props);
IggyStreamConfig config = new IggyStreamConfig(streamConfig);

assertEquals("123", config.getStreamId());
assertEquals("456", config.getTopicId());
assertThat(config.getStreamId()).isEqualTo("123");
assertThat(config.getTopicId()).isEqualTo("456");
}

private Map<String, String> createValidConfig() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,14 @@
import java.util.ArrayList;
import java.util.List;

import static org.junit.jupiter.api.Assertions.assertArrayEquals;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.assertj.core.api.Assertions.assertThat;

class IggyMessageBatchTest {

@Test
void testEmptyBatch() {
IggyMessageBatch batch = new IggyMessageBatch(new ArrayList<>());
assertEquals(0, batch.getMessageCount());
assertThat(batch.getMessageCount()).isEqualTo(0);
}

@Test
Expand All @@ -46,11 +44,11 @@ void testSingleMessage() {

IggyMessageBatch batch = new IggyMessageBatch(messages);

assertEquals(1, batch.getMessageCount());
assertArrayEquals(payload, batch.getMessageAtIndex(0));
assertEquals(payload.length, batch.getMessageLengthAtIndex(0));
assertEquals(100L, batch.getNextStreamMessageOffsetAtIndex(0));
assertEquals(offset, batch.getNextStreamPartitionMsgOffsetAtIndex(0));
assertThat(batch.getMessageCount()).isEqualTo(1);
assertThat(batch.getMessageAtIndex(0)).isEqualTo(payload);
assertThat(batch.getMessageLengthAtIndex(0)).isEqualTo(payload.length);
assertThat(batch.getNextStreamMessageOffsetAtIndex(0)).isEqualTo(100L);
assertThat(batch.getNextStreamPartitionMsgOffsetAtIndex(0)).isEqualTo(offset);
}

@Test
Expand All @@ -65,14 +63,14 @@ void testMultipleMessages() {

IggyMessageBatch batch = new IggyMessageBatch(messages);

assertEquals(10, batch.getMessageCount());
assertThat(batch.getMessageCount()).isEqualTo(10);

for (int i = 0; i < 10; i++) {
byte[] expectedPayload = ("message-" + i).getBytes(StandardCharsets.UTF_8);
assertArrayEquals(expectedPayload, batch.getMessageAtIndex(i));
assertEquals(expectedPayload.length, batch.getMessageLengthAtIndex(i));
assertEquals(i * 100L, batch.getNextStreamMessageOffsetAtIndex(i));
assertEquals(i, batch.getMessageOffsetAtIndex(i));
assertThat(batch.getMessageAtIndex(i)).isEqualTo(expectedPayload);
assertThat(batch.getMessageLengthAtIndex(i)).isEqualTo(expectedPayload.length);
assertThat(batch.getNextStreamMessageOffsetAtIndex(i)).isEqualTo(i * 100L);
assertThat(batch.getMessageOffsetAtIndex(i)).isEqualTo(i);
}
}

Expand All @@ -83,9 +81,9 @@ void testMessageAndOffsetWrapper() {

IggyMessageBatch.IggyMessageAndOffset wrapper = new IggyMessageBatch.IggyMessageAndOffset(payload, offset);

assertArrayEquals(payload, wrapper.getMessage());
assertEquals(offset, wrapper.getOffset());
assertEquals(123L, wrapper.getOffset().getOffset());
assertThat(wrapper.getMessage()).isEqualTo(payload);
assertThat(wrapper.getOffset()).isEqualTo(offset);
assertThat(wrapper.getOffset().getOffset()).isEqualTo(123L);
}

@Test
Expand All @@ -97,10 +95,10 @@ void testNullOffsetAtInvalidIndex() {

IggyMessageBatch batch = new IggyMessageBatch(messages);

assertNull(batch.getNextStreamPartitionMsgOffsetAtIndex(-1));
assertNull(batch.getNextStreamPartitionMsgOffsetAtIndex(10));
assertEquals(0, batch.getNextStreamMessageOffsetAtIndex(-1));
assertEquals(0, batch.getNextStreamMessageOffsetAtIndex(10));
assertThat(batch.getNextStreamPartitionMsgOffsetAtIndex(-1)).isNull();
assertThat(batch.getNextStreamPartitionMsgOffsetAtIndex(10)).isNull();
assertThat(batch.getNextStreamMessageOffsetAtIndex(-1)).isEqualTo(0);
assertThat(batch.getNextStreamMessageOffsetAtIndex(10)).isEqualTo(0);
}

@Test
Expand All @@ -116,8 +114,8 @@ void testLargeMessageBatch() {

IggyMessageBatch batch = new IggyMessageBatch(messages);

assertEquals(1000, batch.getMessageCount());
assertEquals(1024, batch.getMessageLengthAtIndex(0));
assertEquals(1024, batch.getMessageLengthAtIndex(999));
assertThat(batch.getMessageCount()).isEqualTo(1000);
assertThat(batch.getMessageLengthAtIndex(0)).isEqualTo(1024);
assertThat(batch.getMessageLengthAtIndex(999)).isEqualTo(1024);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,14 @@

import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.assertj.core.api.Assertions.assertThat;

class IggyStreamPartitionMsgOffsetTest {

@Test
void testOffsetCreation() {
IggyStreamPartitionMsgOffset offset = new IggyStreamPartitionMsgOffset(100L);
assertEquals(100L, offset.getOffset());
assertThat(offset.getOffset()).isEqualTo(100L);
}

@Test
Expand All @@ -39,9 +37,9 @@ void testCompareTo() {
IggyStreamPartitionMsgOffset offset2 = new IggyStreamPartitionMsgOffset(200L);
IggyStreamPartitionMsgOffset offset3 = new IggyStreamPartitionMsgOffset(100L);

assertTrue(offset1.compareTo(offset2) < 0);
assertTrue(offset2.compareTo(offset1) > 0);
assertEquals(0, offset1.compareTo(offset3));
assertThat(offset1.compareTo(offset2)).isNegative();
assertThat(offset2.compareTo(offset1)).isPositive();
assertThat(offset1.compareTo(offset3)).isZero();
}

@Test
Expand All @@ -50,11 +48,11 @@ void testEquals() {
IggyStreamPartitionMsgOffset offset2 = new IggyStreamPartitionMsgOffset(100L);
IggyStreamPartitionMsgOffset offset3 = new IggyStreamPartitionMsgOffset(200L);

assertEquals(offset1, offset2);
assertNotEquals(offset1, offset3);
assertEquals(offset1, offset1);
assertNotEquals(offset1, null);
assertNotEquals(offset1, "string");
assertThat(offset1).isEqualTo(offset2);
assertThat(offset1).isNotEqualTo(offset3);
assertThat(offset1).isEqualTo(offset1);
assertThat(offset1).isNotEqualTo(null);
assertThat(offset1).isNotEqualTo("string");
}

@Test
Expand All @@ -63,28 +61,28 @@ void testHashCode() {
IggyStreamPartitionMsgOffset offset2 = new IggyStreamPartitionMsgOffset(100L);
IggyStreamPartitionMsgOffset offset3 = new IggyStreamPartitionMsgOffset(200L);

assertEquals(offset1.hashCode(), offset2.hashCode());
assertNotEquals(offset1.hashCode(), offset3.hashCode());
assertThat(offset1.hashCode()).isEqualTo(offset2.hashCode());
assertThat(offset1.hashCode()).isNotEqualTo(offset3.hashCode());
}

@Test
void testToString() {
IggyStreamPartitionMsgOffset offset = new IggyStreamPartitionMsgOffset(12345L);
assertEquals("12345", offset.toString());
assertThat(offset.toString()).isEqualTo("12345");
}

@Test
void testZeroOffset() {
IggyStreamPartitionMsgOffset offset = new IggyStreamPartitionMsgOffset(0L);
assertEquals(0L, offset.getOffset());
assertEquals("0", offset.toString());
assertThat(offset.getOffset()).isEqualTo(0L);
assertThat(offset.toString()).isEqualTo("0");
}

@Test
void testLargeOffset() {
long largeOffset = Long.MAX_VALUE - 1;
IggyStreamPartitionMsgOffset offset = new IggyStreamPartitionMsgOffset(largeOffset);
assertEquals(largeOffset, offset.getOffset());
assertEquals(String.valueOf(largeOffset), offset.toString());
assertThat(offset.getOffset()).isEqualTo(largeOffset);
assertThat(offset.toString()).isEqualTo(String.valueOf(largeOffset));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
import java.util.concurrent.TimeUnit;

import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.assertj.core.api.Assertions.assertThatThrownBy;

/**
* Dedicated async-specific tests for {@link ConsumerGroupsClient} via
Expand Down Expand Up @@ -382,16 +382,20 @@ void shouldReturnEmptyForNonExistentGroup() throws Exception {
void shouldFailToDeleteNonExistentGroup() {
var future = client.consumerGroups().deleteConsumerGroup(STREAM_ID, TOPIC_ID, ConsumerId.of(999_999L));

var exception = assertThrows(ExecutionException.class, () -> future.get(TIMEOUT_SECONDS, TimeUnit.SECONDS));
assertThat(exception.getCause()).isInstanceOf(IggyResourceNotFoundException.class);
assertThatThrownBy(() -> future.get(TIMEOUT_SECONDS, TimeUnit.SECONDS))
.isInstanceOf(ExecutionException.class)
.cause()
.isInstanceOf(IggyResourceNotFoundException.class);
}

@Test
void shouldFailToJoinNonExistentGroup() {
var future = client.consumerGroups().joinConsumerGroup(STREAM_ID, TOPIC_ID, ConsumerId.of(999_999L));

var exception = assertThrows(ExecutionException.class, () -> future.get(TIMEOUT_SECONDS, TimeUnit.SECONDS));
assertThat(exception.getCause()).isInstanceOf(IggyResourceNotFoundException.class);
assertThatThrownBy(() -> future.get(TIMEOUT_SECONDS, TimeUnit.SECONDS))
.isInstanceOf(ExecutionException.class)
.cause()
.isInstanceOf(IggyResourceNotFoundException.class);
}

@Test
Expand All @@ -404,8 +408,10 @@ void shouldFailToLeaveGroupNotJoined() throws Exception {

var future = client.consumerGroups().leaveConsumerGroup(STREAM_ID, TOPIC_ID, ConsumerId.of(created.id()));

var exception = assertThrows(ExecutionException.class, () -> future.get(TIMEOUT_SECONDS, TimeUnit.SECONDS));
assertThat(exception.getCause()).isInstanceOf(IggyResourceNotFoundException.class);
assertThatThrownBy(() -> future.get(TIMEOUT_SECONDS, TimeUnit.SECONDS))
.isInstanceOf(ExecutionException.class)
.cause()
.isInstanceOf(IggyResourceNotFoundException.class);
}

// ===== CompletableFuture-specific tests =====
Expand Down
Loading
Loading