Skip to content

Commit

Permalink
Merge branch '3.1' into 3.2
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisvest committed Feb 15, 2017
2 parents 18b74da + d5da197 commit b797487
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,10 @@ public synchronized void storeIndexFailure( String failure ) throws IOException
File failureFile = failureFile();
try ( StoreChannel channel = fs.open( failureFile, "rw" ) )
{
byte[] existingData = new byte[(int) channel.size()];
channel.read( ByteBuffer.wrap( existingData ) );
channel.position( lengthOf( existingData ) );

byte[] data = UTF8.encode( failure );
channel.write( ByteBuffer.wrap( data, 0, Math.min( data.length, MAX_FAILURE_SIZE ) ) );

Expand All @@ -135,7 +139,6 @@ private String readFailure( File failureFile ) throws IOException
{
byte[] data = new byte[(int) channel.size()];
int readData = channel.read( ByteBuffer.wrap( data ) );
channel.close();
return readData <= 0 ? "" : UTF8.decode( withoutZeros( data ) );
}
}
Expand All @@ -149,7 +152,7 @@ private static byte[] withoutZeros( byte[] data )

private static int lengthOf( byte[] data )
{
for (int i = 0; i < data.length; i++ )
for ( int i = 0; i < data.length; i++ )
{
if ( 0 == data[i] )
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,12 @@
import org.neo4j.kernel.api.impl.index.storage.layout.IndexFolderLayout;
import org.neo4j.test.rule.fs.EphemeralFileSystemRule;

import static org.hamcrest.CoreMatchers.containsString;

import static java.lang.String.format;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;

public class FailureStorageTest
Expand Down Expand Up @@ -99,4 +102,23 @@ public void shouldClearFailure() throws Exception
// THEN
assertFalse( fs.get().fileExists( failureFile ) );
}

@Test
public void shouldAppendFailureIfAlreadyExists() throws Exception
{
// GIVEN
FailureStorage storage = new FailureStorage( fs.get(), indexFolderLayout );
storage.reserveForIndex();
String failure1 = "Once upon a time there was a first failure";
String failure2 = "Then there was another";
storage.storeIndexFailure( failure1 );

// WHEN
storage.storeIndexFailure( failure2 );

// THEN
String allFailures = storage.loadIndexFailure();
assertThat( allFailures, containsString( failure1 ) );
assertThat( allFailures, containsString( failure2 ) );
}
}

0 comments on commit b797487

Please sign in to comment.