*/
package org.opendaylight.controller.akka.segjournal;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.ArgumentMatchers.any;
-import static org.mockito.Mockito.doNothing;
-import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.reset;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import akka.persistence.PersistentRepr;
import akka.testkit.CallingThreadDispatcher;
import akka.testkit.javadsl.TestKit;
-import io.atomix.storage.StorageLevel;
+import io.atomix.storage.journal.StorageLevel;
import java.io.File;
import java.io.IOException;
import java.io.Serializable;
import java.util.function.Consumer;
import java.util.stream.Collectors;
import org.apache.commons.io.FileUtils;
-import org.junit.After;
-import org.junit.AfterClass;
-import org.junit.Before;
-import org.junit.BeforeClass;
-import org.junit.Test;
+import org.junit.jupiter.api.AfterAll;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+import org.mockito.Mock;
+import org.mockito.junit.jupiter.MockitoExtension;
import org.opendaylight.controller.akka.segjournal.SegmentedJournalActor.AsyncMessage;
import org.opendaylight.controller.akka.segjournal.SegmentedJournalActor.WriteMessages;
import scala.concurrent.Future;
-public class SegmentedFileJournalTest {
+@ExtendWith(MockitoExtension.class)
+class SegmentedFileJournalTest {
private static final File DIRECTORY = new File("target/sfj-test");
private static final int SEGMENT_SIZE = 1024 * 1024;
private static final int MESSAGE_SIZE = 512 * 1024;
+ private static final int FLUSH_SIZE = 16 * 1024;
private static ActorSystem SYSTEM;
+ @Mock
+ private Consumer<PersistentRepr> firstCallback;
+
private TestKit kit;
private ActorRef actor;
- @BeforeClass
- public static void beforeClass() {
+ @BeforeAll
+ static void beforeClass() {
SYSTEM = ActorSystem.create("test");
}
- @AfterClass
- public static void afterClass() {
+ @AfterAll
+ static void afterClass() {
TestKit.shutdownActorSystem(SYSTEM);
SYSTEM = null;
}
- @Before
- public void before() {
+ @BeforeEach
+ void before() {
kit = new TestKit(SYSTEM);
FileUtils.deleteQuietly(DIRECTORY);
actor = actor();
}
- @After
- public void after() {
+ @AfterEach
+ void after() {
actor.tell(PoisonPill.getInstance(), ActorRef.noSender());
+ FileUtils.deleteQuietly(DIRECTORY);
}
@Test
- public void testDeleteAfterStop() {
+ void testDeleteAfterStop() {
// Preliminary setup
final WriteMessages write = new WriteMessages();
final Future<Optional<Exception>> first = write.add(AtomicWrite.apply(PersistentRepr.apply("first", 1, "foo",
}
@Test
- public void testSegmentation() throws IOException {
+ void testSegmentation() throws IOException {
// We want to have roughly three segments
final LargePayload payload = new LargePayload();
}
@Test
- public void testComplexDeletesAndPartialReplays() throws Exception {
+ void testComplexDeletesAndPartialReplays() throws Exception {
for (int i = 0; i <= 4; i++) {
writeBigPaylod();
}
private ActorRef actor() {
return kit.childActorOf(SegmentedJournalActor.props("foo", DIRECTORY, StorageLevel.DISK, MESSAGE_SIZE,
- SEGMENT_SIZE).withDispatcher(CallingThreadDispatcher.Id()));
+ SEGMENT_SIZE, FLUSH_SIZE).withDispatcher(CallingThreadDispatcher.Id()));
}
private void deleteEntries(final long deleteTo) {
}
private void assertReplayCount(final int expected) {
- Consumer<PersistentRepr> firstCallback = mock(Consumer.class);
- doNothing().when(firstCallback).accept(any(PersistentRepr.class));
+ // Cast fixes an Eclipse warning 'generic array created'
+ reset((Object) firstCallback);
AsyncMessage<Void> replay = SegmentedJournalActor.replayMessages(0, Long.MAX_VALUE, Long.MAX_VALUE,
firstCallback);
actor.tell(replay, ActorRef.noSender());
return future.value().get().get();
}
- private static final class LargePayload implements Serializable {
+ static final class LargePayload implements Serializable {
+ @java.io.Serial
private static final long serialVersionUID = 1L;
final byte[] bytes = new byte[MESSAGE_SIZE / 2];
-
}
}