Skip to content

Commit

Permalink
[Java] Test tidyup.
Browse files Browse the repository at this point in the history
  • Loading branch information
mjpt777 committed Jul 14, 2017
1 parent 7280f33 commit 8e12a8a
Show file tree
Hide file tree
Showing 8 changed files with 20 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public class ArchiverSystemTest
private Archiver archiver;
private MediaDriver driver;
private final UnsafeBuffer buffer = new UnsafeBuffer(new byte[4096]);
private File archiveDir;
private File archiveDir = TestUtil.makeTempDir();
private long recordingId;
private long remaining;
private int fragmentCount;
Expand All @@ -79,7 +79,7 @@ public class ArchiverSystemTest
private volatile long endPosition = -1;
private Throwable trackerError;
private final Random rnd = new Random();
private long seed;
private long seed = System.nanoTime();

@Rule
public TestWatcher testWatcher = new TestWatcher()
Expand All @@ -98,10 +98,9 @@ protected void failed(final Throwable t, final Description description)
@Before
public void before() throws Exception
{
seed = System.nanoTime();
rnd.setSeed(seed);

requestedInitialTermId = rnd.nextInt(1234);

final int termLength = 1 << (16 + rnd.nextInt(10)); // 1M to 8M
final int mtu = 1 << (10 + rnd.nextInt(3)); // 1024 to 8096
final int termOffset = BitUtil.align(rnd.nextInt(termLength), FrameDescriptor.FRAME_ALIGNMENT);
Expand Down Expand Up @@ -131,13 +130,11 @@ public void before() throws Exception

driver = MediaDriver.launch(driverCtx);

final int segmentFileLength = termLength << rnd.nextInt(4);
archiveDir = TestUtil.makeTempDir();
archiverCtx
.fileSyncLevel(0)
.mediaDriverAgentInvoker(driver.sharedAgentInvoker())
.archiveDir(archiveDir)
.segmentFileLength(segmentFileLength)
.segmentFileLength(termLength << rnd.nextInt(4))
.threadingMode(archiverThreadingMode())
.countersManager(driverCtx.countersManager())
.errorHandler(driverCtx.errorHandler());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public class CatalogTest
private long recordingOneId;
private long recordingTwoId;
private long recordingThreeId;
private File archiveDir;
private File archiveDir = TestUtil.makeTempDir();

@Before
public void before() throws Exception
Expand All @@ -45,7 +45,6 @@ public void before() throws Exception
Catalog.CATALOG_FRAME_LENGTH,
RecordingDescriptorDecoder.BLOCK_LENGTH,
RecordingDescriptorDecoder.SCHEMA_VERSION);
archiveDir = TestUtil.makeTempDir();

try (Catalog catalog = new Catalog(archiveDir, null, 0))
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public class RecordingSessionTest
private final RecordingEventsProxy recordingEventsProxy = mock(RecordingEventsProxy.class);
private Image image = mockImage(
SESSION_ID, INITIAL_TERM_ID, SOURCE_IDENTITY, TERM_BUFFER_LENGTH, mockSubscription(CHANNEL, STREAM_ID));
private File tempDirForTest;
private File tempDirForTest = TestUtil.makeTempDir();
private FileChannel mockLogBufferChannel;
private UnsafeBuffer mockLogBufferMapped;
private File termFile;
Expand All @@ -76,8 +76,6 @@ public class RecordingSessionTest
@Before
public void before() throws IOException
{
tempDirForTest = TestUtil.makeTempDir();

termFile = File.createTempFile("test.rec", "sourceIdentity");

mockLogBufferChannel = FileChannel.open(termFile.toPath(), CREATE, READ, WRITE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public class RecordingWriterTest
private static final int SYNC_LEVEL = 2;
private static final String CHANNEL = "channel";
private static final String SOURCE = "source";
private File archiveDir;
private File archiveDir = TestUtil.makeTempDir();
private EpochClock epochClock = Mockito.mock(EpochClock.class);
private final RecordingWriter.Context recordingCtx = new RecordingWriter.Context();
private FileChannel mockArchiveDirFileChannel = Mockito.mock(FileChannel.class);
Expand All @@ -42,7 +42,6 @@ public class RecordingWriterTest
@Before
public void before() throws Exception
{
archiveDir = TestUtil.makeTempDir();
recordingCtx
.archiveDirChannel(mockArchiveDirFileChannel)
.archiveDir(archiveDir)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public class ReplaySessionTest
Mockito.mock(ArchiveConductor.ReplayPublicationSupplier.class);
private int messageCounter = 0;

private File archiveDir;
private File archiveDir = makeTempDir();
private ControlSessionProxy proxy = Mockito.mock(ControlSessionProxy.class);
private EpochClock epochClock = mock(EpochClock.class);
private RecordingWriter.Context context;
Expand All @@ -76,8 +76,6 @@ public class ReplaySessionTest
@Before
public void before() throws Exception
{
archiveDir = makeTempDir();

context = new RecordingWriter.Context()
.archiveDir(archiveDir)
.epochClock(epochClock);
Expand Down
12 changes: 10 additions & 2 deletions aeron-archiver/src/test/java/io/aeron/archiver/TestUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,17 @@ public class TestUtil
static final boolean DEBUG = false;
private static final int SLEEP_TIME_NS = 5000;

public static File makeTempDir() throws IOException
public static File makeTempDir()
{
final File tempDirForTest = File.createTempFile("archiver", "tmp");
final File tempDirForTest;
try
{
tempDirForTest = File.createTempFile("archiver", "tmp");
}
catch (final IOException ex)
{
throw new RuntimeException(ex);
}

Assert.assertTrue(tempDirForTest.delete());
Assert.assertTrue(tempDirForTest.mkdir());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public class ArchiveRecordingLoadTest
private Archiver archiver;
private MediaDriver driver;
private final UnsafeBuffer buffer = new UnsafeBuffer(new byte[4096]);
private File archiveDir;
private File archiveDir = TestUtil.makeTempDir();
private long recordingId;
private int[] fragmentLength;
private long totalDataLength;
Expand Down Expand Up @@ -101,7 +101,6 @@ public void setUp() throws Exception

driver = MediaDriver.launch(driverCtx);

archiveDir = TestUtil.makeTempDir();
archiverCtx
.fileSyncLevel(2)
.archiveDir(archiveDir)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public class ArchiveReplayLoadTest
private Archiver archiver;
private MediaDriver driver;
private UnsafeBuffer buffer = new UnsafeBuffer(new byte[4096]);
private File archiveDir;
private File archiveDir = TestUtil.makeTempDir();
private final long recordingId = 0;
private long remaining;
private int fragmentCount;
Expand Down Expand Up @@ -107,7 +107,6 @@ public void setUp() throws Exception

driver = MediaDriver.launch(driverCtx);

archiveDir = TestUtil.makeTempDir();
archiverCtx
.archiveDir(archiveDir)
.fileSyncLevel(0)
Expand Down

0 comments on commit 8e12a8a

Please sign in to comment.