-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
229 additions
and
5 deletions.
There are no files selected for viewing
13 changes: 13 additions & 0 deletions
13
api/src/main/java/com/github/bsideup/liiklus/records/FiniteRecordsStorage.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package com.github.bsideup.liiklus.records; | ||
|
||
import java.util.Map; | ||
import java.util.concurrent.CompletionStage; | ||
|
||
public interface FiniteRecordsStorage extends RecordsStorage { | ||
|
||
/** | ||
* Returns a {@link Map} where key is partition's number and value is the latest offset. | ||
* The offset can be zero. Offset -1 means that there is no offset for this partition. | ||
*/ | ||
CompletionStage<Map<Integer, Long>> getEndOffsets(String topic); | ||
} |
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
57 changes: 57 additions & 0 deletions
57
app/src/test/java/com/github/bsideup/liiklus/EndOffsetsTest.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package com.github.bsideup.liiklus; | ||
|
||
import com.github.bsideup.liiklus.protocol.GetEndOffsetsRequest; | ||
import com.github.bsideup.liiklus.protocol.PublishRequest; | ||
import com.github.bsideup.liiklus.test.AbstractIntegrationTest; | ||
import com.google.protobuf.ByteString; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
|
||
import java.util.UUID; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
public class EndOffsetsTest extends AbstractIntegrationTest { | ||
|
||
private String topic; | ||
|
||
@Before | ||
public final void setUpEndOffsetsTest() { | ||
topic = testName.getMethodName(); | ||
} | ||
|
||
@Test | ||
public void testEndOffsets() { | ||
var value = ByteString.copyFromUtf8("foo"); | ||
|
||
for (int partition = 0; partition < NUM_PARTITIONS; partition++) { | ||
for (int i = 0; i < partition + 1; i++) { | ||
stub.publish(PublishRequest.newBuilder() | ||
.setTopic(topic) | ||
.setKey(ByteString.copyFromUtf8(PARTITION_KEYS.get(partition))) | ||
.setValue(value) | ||
.build() | ||
).block(); | ||
} | ||
} | ||
|
||
var reply = stub.getEndOffsets(GetEndOffsetsRequest.newBuilder().setTopic(topic).build()).block(); | ||
|
||
assertThat(reply.getOffsetsMap()) | ||
.hasSize(NUM_PARTITIONS) | ||
.allSatisfy((partition, offset) -> { | ||
assertThat(offset) | ||
.as("offset of p" + partition) | ||
.isEqualTo(partition.longValue()); | ||
}); | ||
} | ||
|
||
@Test | ||
public void testEndOffsets_unknownTopic() { | ||
var randomTopic = UUID.randomUUID().toString(); | ||
var reply = stub.getEndOffsets(GetEndOffsetsRequest.newBuilder().setTopic(randomTopic).build()).block(); | ||
|
||
assertThat(reply.getOffsetsMap()).isEmpty(); | ||
} | ||
|
||
} |
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
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
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
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
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
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
67 changes: 67 additions & 0 deletions
67
tck/src/main/java/com/github/bsideup/liiklus/records/tests/EndOffsetsTest.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
package com.github.bsideup.liiklus.records.tests; | ||
|
||
import com.github.bsideup.liiklus.records.FiniteRecordsStorage; | ||
import com.github.bsideup.liiklus.records.RecordStorageTestSupport; | ||
import org.junit.jupiter.api.Assumptions; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.TestInfo; | ||
|
||
import java.lang.reflect.Method; | ||
import java.util.UUID; | ||
import java.util.concurrent.TimeUnit; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
public interface EndOffsetsTest extends RecordStorageTestSupport { | ||
|
||
default FiniteRecordsStorage getFiniteTarget() { | ||
return (FiniteRecordsStorage) getTarget(); | ||
} | ||
|
||
int getNumberOfPartitions(); | ||
|
||
String keyByPartition(int partition); | ||
|
||
@BeforeEach | ||
default void blah(TestInfo testInfo) { | ||
if (EndOffsetsTest.class == testInfo.getTestMethod().map(Method::getDeclaringClass).orElse(null)) { | ||
Assumptions.assumeTrue(getTarget() instanceof FiniteRecordsStorage, "target is finite"); | ||
} | ||
} | ||
|
||
@Test | ||
default void testEndOffsets() throws Exception { | ||
var topic = getTopic(); | ||
|
||
for (int partition = 0; partition < getNumberOfPartitions(); partition++) { | ||
for (int i = 0; i < partition + 1; i++) { | ||
publish(keyByPartition(partition).getBytes(), new byte[1]); | ||
} | ||
} | ||
|
||
var offsets = getFiniteTarget().getEndOffsets(topic).toCompletableFuture().get(10, TimeUnit.SECONDS); | ||
|
||
assertThat(offsets) | ||
.hasSize(getNumberOfPartitions()) | ||
.allSatisfy((partition, offset) -> { | ||
assertThat(offset) | ||
.as("offset of p" + partition) | ||
.isEqualTo(partition.longValue()); | ||
}); | ||
} | ||
|
||
@Test | ||
default void testEndOffsets_unknownTopic() throws Exception { | ||
var topic = UUID.randomUUID().toString(); | ||
|
||
var offsets = getFiniteTarget().getEndOffsets(topic).toCompletableFuture().get(10, TimeUnit.SECONDS); | ||
|
||
assertThat(offsets) | ||
.allSatisfy((partition, offset) -> { | ||
assertThat(offset) | ||
.as("offset of p" + partition) | ||
.isEqualTo(-1L); | ||
}); | ||
} | ||
} |