Skip to content

Commit

Permalink
Parameterize segmented log contract test.
Browse files Browse the repository at this point in the history
The idea is that functional behaviour should not change due to no
cache or different cache sizes.
  • Loading branch information
martinfurmanski committed May 9, 2016
1 parent 9c7ce4a commit c854c37
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 20 deletions.
Expand Up @@ -28,7 +28,7 @@
import org.neo4j.cursor.IOCursor;

/**
* The entrie store allows iterating over RAFT log entries efficiently and handles moving from one
* The entry store allows iterating over RAFT log entries efficiently and handles moving from one
* segment to the next in a transparent manner. It can thus be mainly viewed as a factory for a
* smart segment-crossing cursor.
*/
Expand Down
Expand Up @@ -19,8 +19,6 @@
*/
package org.neo4j.coreedge.raft.log.segmented;

import org.neo4j.coreedge.raft.log.segmented.Segments;

/**
* Collects all the state that must be recovered after a restart.
*/
Expand Down
Expand Up @@ -30,7 +30,6 @@
import org.junit.Test;
import org.neo4j.coreedge.raft.log.DamagedLogStorageException;
import org.neo4j.coreedge.raft.log.DummyRaftableContentSerializer;
import org.neo4j.coreedge.raft.log.segmented.SegmentHeader;
import org.neo4j.coreedge.raft.replication.ReplicatedContent;
import org.neo4j.coreedge.raft.state.ChannelMarshal;
import org.neo4j.graphdb.mockfs.EphemeralFileSystemAbstraction;
Expand Down
Expand Up @@ -20,10 +20,13 @@
package org.neo4j.coreedge.raft.log.segmented;

import java.io.File;
import java.io.IOException;
import java.util.Arrays;
import java.util.Collection;

import org.junit.After;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;

import org.neo4j.coreedge.raft.ReplicatedInteger;
import org.neo4j.coreedge.raft.log.DummyRaftableContentSerializer;
Expand All @@ -39,18 +42,29 @@

import static org.neo4j.coreedge.raft.log.RaftLogHelper.readLogEntry;

// TODO: Separate into small-cache and no-cache tests. Perhaps parameterize this one (0, 5, 1024) cache sizes.
@RunWith(Parameterized.class)
public class SegmentedRaftLogContractTest extends RaftLogContractTest
{
private SegmentedRaftLog raftLog;
private LifeSupport life = new LifeSupport();
private FileSystemAbstraction fileSystem;

@Override
public RaftLog createRaftLog() throws IOException
// parameter
private int cacheSize;

@Parameterized.Parameters(name = "cacheSize:{0}")
public static Collection<Object[]> data()
{
return Arrays.asList(new Object[][]{
{0},
{5},
{1024},
});
}

public SegmentedRaftLogContractTest( int cacheSize )
{
this.raftLog = createRaftLog( 0 );
return raftLog;
this.cacheSize = cacheSize;
}

@After
Expand All @@ -60,7 +74,8 @@ public void tearDown() throws Throwable
life.shutdown();
}

private SegmentedRaftLog createRaftLog( int cacheSize )
@Override
public RaftLog createRaftLog()
{
if ( fileSystem == null )
{
Expand All @@ -69,7 +84,7 @@ private SegmentedRaftLog createRaftLog( int cacheSize )
File directory = new File( "raft-log" );
fileSystem.mkdir( directory );

SegmentedRaftLog newRaftLog = new SegmentedRaftLog( fileSystem, directory, 10 * 1024,
SegmentedRaftLog newRaftLog = new SegmentedRaftLog( fileSystem, directory, 1024,
new DummyRaftableContentSerializer(),
NullLogProvider.getInstance(), cacheSize );
life.add( newRaftLog );
Expand Down Expand Up @@ -99,8 +114,7 @@ public void shouldReadBackInCachedEntry() throws Throwable
public void shouldReadBackNonCachedEntry() throws Exception
{
// Given
int cacheSize = 1;
SegmentedRaftLog raftLog = createRaftLog( cacheSize );
RaftLog raftLog = createRaftLog();
int term = 0;
ReplicatedInteger content1 = ReplicatedInteger.valueOf( 4 );
ReplicatedInteger content2 = ReplicatedInteger.valueOf( 5 );
Expand All @@ -123,7 +137,7 @@ public void shouldReadBackNonCachedEntry() throws Exception
public void shouldRestoreCommitIndexOnStartup() throws Throwable
{
// Given
SegmentedRaftLog raftLog = createRaftLog( 100 /* cache size */ );
RaftLog raftLog = createRaftLog();
int term = 0;
ReplicatedInteger content1 = ReplicatedInteger.valueOf( 4 );
ReplicatedInteger content2 = ReplicatedInteger.valueOf( 5 );
Expand All @@ -133,7 +147,7 @@ public void shouldRestoreCommitIndexOnStartup() throws Throwable
// When
// we restart the raft log
life.remove( raftLog ); // stops the removed instance
raftLog = createRaftLog( 100 );
raftLog = createRaftLog();

// Then
assertEquals( entryIndex2, raftLog.appendIndex() );
Expand All @@ -143,7 +157,7 @@ public void shouldRestoreCommitIndexOnStartup() throws Throwable
public void shouldRestoreCorrectCommitAndAppendIndexOnStartupAfterTruncation() throws Exception
{
// Given
SegmentedRaftLog raftLog = createRaftLog( 100 /* cache size */ );
RaftLog raftLog = createRaftLog();
int term = 0;
ReplicatedInteger content = ReplicatedInteger.valueOf( 4 );
raftLog.append( new RaftLogEntry( term, content ) );
Expand All @@ -156,7 +170,7 @@ public void shouldRestoreCorrectCommitAndAppendIndexOnStartupAfterTruncation() t
// When
// we restart the raft log
life.remove( raftLog ); // stops the removed instance
raftLog = createRaftLog( 100 );
raftLog = createRaftLog();

// Then
assertEquals( entryIndex3, raftLog.appendIndex() );
Expand All @@ -166,7 +180,7 @@ public void shouldRestoreCorrectCommitAndAppendIndexOnStartupAfterTruncation() t
public void shouldRestoreCorrectCommitAndAppendIndexWithTruncationRecordsAndAppendedRecordsAfterThat() throws Exception
{
// Given
SegmentedRaftLog raftLog = createRaftLog( 100 /* cache size */ );
RaftLog raftLog = createRaftLog();
int term = 0;
ReplicatedInteger content = ReplicatedInteger.valueOf( 4 );
raftLog.append( new RaftLogEntry( term, content ) );
Expand All @@ -181,7 +195,7 @@ public void shouldRestoreCorrectCommitAndAppendIndexWithTruncationRecordsAndAppe
// When
// we restart the raft log
life.remove( raftLog ); // stops the removed instance
raftLog = createRaftLog( 100 );
raftLog = createRaftLog();

// Then
assertEquals( entryIndex5, raftLog.appendIndex() );
Expand Down

0 comments on commit c854c37

Please sign in to comment.