-
Notifications
You must be signed in to change notification settings - Fork 601
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(logstreams): verify failed writer creation
(cherry picked from commit c649178)
- Loading branch information
1 parent
9f017a0
commit d160848
Showing
1 changed file
with
69 additions
and
0 deletions.
There are no files selected for viewing
69 changes: 69 additions & 0 deletions
69
logstreams/src/test/java/io/camunda/zeebe/logstreams/log/LogStreamErrorTest.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,69 @@ | ||
/* | ||
* Copyright Camunda Services GmbH and/or licensed to Camunda Services GmbH under | ||
* one or more contributor license agreements. See the NOTICE file distributed | ||
* with this work for additional information regarding copyright ownership. | ||
* Licensed under the Zeebe Community License 1.1. You may not use this file | ||
* except in compliance with the Zeebe Community License 1.1. | ||
*/ | ||
package io.camunda.zeebe.logstreams.log; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static org.mockito.Mockito.mock; | ||
import static org.mockito.Mockito.when; | ||
|
||
import io.camunda.zeebe.logstreams.storage.LogStorage; | ||
import io.camunda.zeebe.logstreams.util.SyncLogStream; | ||
import io.camunda.zeebe.util.sched.testing.ActorSchedulerRule; | ||
import org.awaitility.Awaitility; | ||
import org.junit.After; | ||
import org.junit.Before; | ||
import org.junit.Rule; | ||
import org.junit.Test; | ||
|
||
public class LogStreamErrorTest { | ||
|
||
@Rule public ActorSchedulerRule actorSchedulerRule = new ActorSchedulerRule(); | ||
final LogStorage mockLogStorage = mock(LogStorage.class); | ||
private SyncLogStream logStream; | ||
|
||
@Before | ||
public void setup() { | ||
logStream = | ||
SyncLogStream.builder() | ||
.withLogName("test-log") | ||
.withLogStorage(mockLogStorage) | ||
.withActorSchedulingService(actorSchedulerRule.get()) | ||
.build(); | ||
|
||
when(mockLogStorage.newReader()).thenThrow(new RuntimeException("reader cannot be created")); | ||
} | ||
|
||
@After | ||
public void after() { | ||
logStream.close(); | ||
} | ||
|
||
@Test | ||
public void shouldCompleteFutureWhenCreateWriterFailed() { | ||
// given | ||
final var writerFuture = logStream.getAsyncLogStream().newLogStreamRecordWriter(); | ||
|
||
// when | ||
Awaitility.await().until(writerFuture::isDone); | ||
|
||
// then | ||
assertThat(writerFuture.isCompletedExceptionally()).isTrue(); | ||
} | ||
|
||
@Test | ||
public void shouldCompleteFutureWhenCreateBatchWriterFailed() { | ||
// given | ||
final var writerFuture = logStream.getAsyncLogStream().newLogStreamBatchWriter(); | ||
|
||
// when | ||
Awaitility.await().until(writerFuture::isDone); | ||
|
||
// then | ||
assertThat(writerFuture.isCompletedExceptionally()).isTrue(); | ||
} | ||
} |