Skip to content

Commit

Permalink
test(dispatcher): update dispatcher unit test to junit 5
Browse files Browse the repository at this point in the history
  • Loading branch information
npepinpe committed Feb 17, 2022
1 parent 471f3c7 commit 409a7dc
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 19 deletions.
6 changes: 6 additions & 0 deletions dispatcher/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,12 @@
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,15 @@
import java.nio.ByteBuffer;
import java.nio.charset.StandardCharsets;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.mockito.Mockito;

public final class DispatcherTest {
final class DispatcherTest {

static final byte[] A_MSG_PAYLOAD = "some bytes".getBytes(StandardCharsets.UTF_8);
static final int A_MSG_PAYLOAD_LENGTH = A_MSG_PAYLOAD.length;
static final int A_FRAGMENT_LENGTH = align(A_MSG_PAYLOAD_LENGTH + HEADER_LENGTH, FRAME_ALIGNMENT);
static final int AN_INITIAL_PARTITION_ID = 0;
static final int A_LOG_WINDOW_LENGTH = 128;
static final int A_PARTITION_SIZE = 1024;
static final int A_STREAM_ID = 20;
Expand All @@ -57,8 +56,8 @@ public final class DispatcherTest {
ClaimedFragmentBatch claimedFragmentBatch;
AtomicPosition subscriberPosition;

@Before
public void setup() {
@BeforeEach
void beforeEach() {
logBuffer = mock(LogBuffer.class);
logBufferPartition0 = mock(LogBufferPartition.class);
logBufferPartition1 = mock(LogBufferPartition.class);
Expand Down Expand Up @@ -110,7 +109,7 @@ protected Subscription newSubscription(
}

@Test
public void shouldNotClaimBeyondPublisherLimit() {
void shouldNotClaimBeyondPublisherLimit() {
// given
// position of 0,0
when(logBuffer.getActivePartitionIdVolatile()).thenReturn(0);
Expand All @@ -134,7 +133,7 @@ public void shouldNotClaimBeyondPublisherLimit() {
}

@Test
public void canClaimFragmentBatch() {
void canClaimFragmentBatch() {
// given
final int fragmentCount = 2;
final int batchLength = dispatcher.getMaxFragmentLength() / 2;
Expand All @@ -147,7 +146,7 @@ public void canClaimFragmentBatch() {
}

@Test
public void cannotClaimFragmentBatch() {
void cannotClaimFragmentBatch() {
// given - a fragment of max length, unframed
final int fragmentCount = 1;
final int batchLength = 2 * dispatcher.getMaxFragmentLength();
Expand All @@ -160,7 +159,7 @@ public void cannotClaimFragmentBatch() {
}

@Test
public void cannotClaimFragmentBatchOfMaxLength() {
void cannotClaimFragmentBatchOfMaxLength() {
// given - a fragment of max length, unframed
final int fragmentCount = 1;
final int batchLength = dispatcher.getMaxFragmentLength();
Expand All @@ -175,7 +174,7 @@ public void cannotClaimFragmentBatchOfMaxLength() {
}

@Test
public void shouldClaimFragment() {
void shouldClaimFragment() {
// given
// position is 0,0
when(logBuffer.getActivePartitionIdVolatile()).thenReturn(0);
Expand Down Expand Up @@ -216,7 +215,7 @@ public void shouldClaimFragment() {
}

@Test
public void shouldReadFragmentsFromPartition() {
void shouldReadFragmentsFromPartition() {
// given
dispatcher.doOpenSubscription("test", mock(ActorCondition.class));
when(subscriberPosition.get()).thenReturn(0L);
Expand All @@ -239,7 +238,7 @@ public void shouldReadFragmentsFromPartition() {
}

@Test
public void shouldNotReadBeyondPublisherPosition() {
void shouldNotReadBeyondPublisherPosition() {
// given
dispatcher.doOpenSubscription("test", mock(ActorCondition.class));
when(subscriptionSpy.getPosition()).thenReturn(0L);
Expand All @@ -253,7 +252,7 @@ public void shouldNotReadBeyondPublisherPosition() {
}

@Test
public void shouldUpdatePublisherLimit() {
void shouldUpdatePublisherLimit() {
when(subscriberPosition.get()).thenReturn(position(10, 100));

dispatcher.doOpenSubscription("test", mock(ActorCondition.class));
Expand All @@ -263,7 +262,7 @@ public void shouldUpdatePublisherLimit() {
}

@Test
public void shouldUpdatePublisherLimitToNextPartition() {
void shouldUpdatePublisherLimitToNextPartition() {
when(subscriberPosition.get()).thenReturn(position(10, A_PARTITION_SIZE - A_LOG_WINDOW_LENGTH));

dispatcher.doOpenSubscription("test", mock(ActorCondition.class));
Expand All @@ -273,7 +272,7 @@ public void shouldUpdatePublisherLimitToNextPartition() {
}

@Test
public void shouldReadFragmentsFromPartitionOnPeekAndConsume() {
void shouldReadFragmentsFromPartitionOnPeekAndConsume() {
// given
dispatcher.doOpenSubscription("test", mock(ActorCondition.class));
when(subscriberPosition.get()).thenReturn(0L);
Expand All @@ -296,7 +295,7 @@ public void shouldReadFragmentsFromPartitionOnPeekAndConsume() {
}

@Test
public void shouldNotOpenSubscriptionWithSameName() {
void shouldNotOpenSubscriptionWithSameName() {
dispatcher.doOpenSubscription("s1", mock(ActorCondition.class));
Assert.assertThrows(
"subscription with name 's1' already exists",
Expand All @@ -305,7 +304,7 @@ public void shouldNotOpenSubscriptionWithSameName() {
}

@Test
public void shouldIncrementRecordPositionAfterClaimingFragment() {
void shouldIncrementRecordPositionAfterClaimingFragment() {
// given
when(publisherLimit.get()).thenReturn(position(0, A_FRAGMENT_LENGTH));
when(logAppender.claim(
Expand All @@ -329,7 +328,7 @@ public void shouldIncrementRecordPositionAfterClaimingFragment() {
}

@Test
public void shouldIncreasePositionByFragmentCountAfterClaimingBatch() {
void shouldIncreasePositionByFragmentCountAfterClaimingBatch() {
// given
final int fragmentCount = 3;
when(logBuffer.getActivePartitionIdVolatile()).thenReturn(0);
Expand Down

0 comments on commit 409a7dc

Please sign in to comment.