-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor tests so they can be reused for all transport protocols
- Loading branch information
1 parent
d43878b
commit ffc65ff
Showing
13 changed files
with
304 additions
and
204 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package rs.iggy; | ||
|
||
import rs.iggy.consumergroup.ConsumerGroupsClient; | ||
import rs.iggy.consumeroffset.ConsumerOffsetsClient; | ||
import rs.iggy.message.MessagesClient; | ||
import rs.iggy.partition.PartitionsClient; | ||
import rs.iggy.stream.StreamsClient; | ||
import rs.iggy.system.SystemClient; | ||
import rs.iggy.topic.TopicsClient; | ||
import rs.iggy.user.UsersClient; | ||
|
||
public interface IggyClient { | ||
|
||
SystemClient system(); | ||
|
||
StreamsClient streams(); | ||
|
||
UsersClient users(); | ||
|
||
TopicsClient topics(); | ||
|
||
PartitionsClient partitions(); | ||
|
||
ConsumerGroupsClient consumerGroups(); | ||
|
||
ConsumerOffsetsClient consumerOffsets(); | ||
|
||
MessagesClient messages(); | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 18 additions & 7 deletions
25
...est/java/rs/iggy/BaseIntegrationTest.java → src/test/java/rs/iggy/IntegrationTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 0 additions & 16 deletions
16
src/test/java/rs/iggy/http/BaseHttpClientIntegrationTest.java
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package rs.iggy.http; | ||
|
||
import org.testcontainers.containers.GenericContainer; | ||
import static rs.iggy.IntegrationTest.HTTP_PORT; | ||
|
||
class HttpClientFactory { | ||
|
||
static IggyHttpClient create(GenericContainer iggyServer) { | ||
String address = iggyServer.getHost(); | ||
Integer port = iggyServer.getMappedPort(HTTP_PORT); | ||
return new IggyHttpClient("http://" + address + ":" + port); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,86 +1,13 @@ | ||
package rs.iggy.http; | ||
|
||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
import rs.iggy.message.*; | ||
import java.math.BigInteger; | ||
import java.nio.ByteBuffer; | ||
import java.util.List; | ||
import java.util.UUID; | ||
import static java.util.Optional.empty; | ||
import static org.assertj.core.api.Assertions.assertThat; | ||
import rs.iggy.IggyClient; | ||
import rs.iggy.message.MessagesClientBaseTest; | ||
|
||
class MessagesHttpClientTest extends BaseHttpClientIntegrationTest { | ||
class MessagesHttpClientTest extends MessagesClientBaseTest { | ||
|
||
MessagesClient messagesClient; | ||
|
||
@BeforeEach | ||
void beforeEach() { | ||
messagesClient = client.messages(); | ||
|
||
login(client); | ||
} | ||
|
||
@Test | ||
void shouldSendAndGetMessages() { | ||
// given | ||
setUpStreamAndTopic(client); | ||
|
||
// when | ||
String text = "message from java sdk"; | ||
messagesClient.sendMessages(42L, 42L, Partitioning.partitionId(1L), | ||
List.of(new MessageToSend(getRandomId(), text.getBytes(), empty()))); | ||
|
||
var polledMessages = messagesClient.pollMessages(42L, 42L, empty(), 0L, | ||
new PollingStrategy(PollingKind.Last, BigInteger.TEN), 10L, false); | ||
|
||
// then | ||
assertThat(polledMessages.messages()).hasSize(1); | ||
} | ||
|
||
@Test | ||
void shouldSendMessageWithBalancedPartitioning() { | ||
// given | ||
setUpStreamAndTopic(client); | ||
|
||
// when | ||
String text = "message from java sdk"; | ||
messagesClient.sendMessages(42L, 42L, Partitioning.balanced(), | ||
List.of(new MessageToSend(getRandomId(), text.getBytes(), empty()))); | ||
|
||
var polledMessages = messagesClient.pollMessages(42L, 42L, empty(), 0L, | ||
new PollingStrategy(PollingKind.Last, BigInteger.TEN), 10L, false); | ||
|
||
// then | ||
assertThat(polledMessages.messages()).hasSize(1); | ||
} | ||
|
||
@Test | ||
void shouldSendMessageWithMessageKeyPartitioning() { | ||
// given | ||
setUpStreamAndTopic(client); | ||
|
||
// when | ||
String text = "message from java sdk"; | ||
messagesClient.sendMessages(42L, 42L, Partitioning.messagesKey("test-key"), | ||
List.of(new MessageToSend(getRandomId(), text.getBytes(), empty()))); | ||
|
||
var polledMessages = messagesClient.pollMessages(42L, 42L, empty(), 0L, | ||
new PollingStrategy(PollingKind.Last, BigInteger.TEN), 10L, false); | ||
|
||
// then | ||
assertThat(polledMessages.messages()).hasSize(1); | ||
} | ||
|
||
private static BigInteger getRandomId() { | ||
return new BigInteger(1, uuidToBytes(UUID.randomUUID())); | ||
} | ||
|
||
private static byte[] uuidToBytes(UUID uuid) { | ||
ByteBuffer byteBuffer = ByteBuffer.wrap(new byte[16]); | ||
byteBuffer.putLong(uuid.getMostSignificantBits()); | ||
byteBuffer.putLong(uuid.getLeastSignificantBits()); | ||
return byteBuffer.array(); | ||
@Override | ||
protected IggyClient getClient() { | ||
return HttpClientFactory.create(iggyServer); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,45 +1,13 @@ | ||
package rs.iggy.http; | ||
|
||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
import rs.iggy.partition.PartitionsClient; | ||
import rs.iggy.topic.TopicDetails; | ||
import rs.iggy.topic.TopicsClient; | ||
import static org.assertj.core.api.Assertions.assertThat; | ||
import rs.iggy.IggyClient; | ||
import rs.iggy.partition.PartitionsClientBaseTest; | ||
|
||
class PartitionsHttpClientTest extends BaseHttpClientIntegrationTest { | ||
class PartitionsHttpClientTest extends PartitionsClientBaseTest { | ||
|
||
TopicsClient topicsClient; | ||
PartitionsClient partitionsClient; | ||
|
||
@BeforeEach | ||
void beforeEach() { | ||
topicsClient = client.topics(); | ||
partitionsClient = client.partitions(); | ||
|
||
login(client); | ||
setUpStreamAndTopic(client); | ||
} | ||
|
||
|
||
@Test | ||
void shouldCreateAndDeletePartitions() { | ||
// given | ||
assert topicsClient.getTopic(42L, 42L).partitionsCount() == 1L; | ||
|
||
// when | ||
partitionsClient.createPartitions(42L, 42L, 10L); | ||
|
||
// then | ||
TopicDetails topic = topicsClient.getTopic(42L, 42L); | ||
assertThat(topic.partitionsCount()).isEqualTo(11L); | ||
|
||
// when | ||
partitionsClient.deletePartitions(42L, 42L, 10L); | ||
|
||
// then | ||
topic = topicsClient.getTopic(42L, 42L); | ||
assertThat(topic.partitionsCount()).isEqualTo(1L); | ||
@Override | ||
protected IggyClient getClient() { | ||
return HttpClientFactory.create(iggyServer); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,38 +1,13 @@ | ||
package rs.iggy.http; | ||
|
||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
import rs.iggy.stream.StreamsClient; | ||
import static org.assertj.core.api.Assertions.assertThat; | ||
import rs.iggy.IggyClient; | ||
import rs.iggy.stream.StreamClientBaseTest; | ||
|
||
class StreamHttpClientTest extends BaseHttpClientIntegrationTest { | ||
class StreamHttpClientTest extends StreamClientBaseTest { | ||
|
||
StreamsClient streamsClient; | ||
|
||
@BeforeEach | ||
void beforeEach() { | ||
streamsClient = client.streams(); | ||
|
||
login(client); | ||
} | ||
|
||
@Test | ||
void shouldCreateAndDeleteStream() { | ||
// when | ||
streamsClient.createStream(42L, "test-stream"); | ||
var stream = streamsClient.getStream(42L); | ||
|
||
// then | ||
assertThat(stream).isNotNull(); | ||
assertThat(stream.id()).isEqualTo(42L); | ||
assertThat(stream.name()).isEqualTo("test-stream"); | ||
|
||
// when | ||
streamsClient.deleteStream(42L); | ||
var streams = streamsClient.getStreams(); | ||
|
||
// then | ||
assertThat(streams).isEmpty(); | ||
@Override | ||
protected IggyClient getClient() { | ||
return HttpClientFactory.create(iggyServer); | ||
} | ||
|
||
} |
Oops, something went wrong.