Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
AFS to only gunk up part of byte[] it has access to
Before this commit, AdversarialFileSystem will inject random data into the complete array given to `getBytes(..)`; meaning a call like `getBytes(bigBuffer, 1000, 10)` could lead to the entire buffer being messed up, rather than just the range the user has asked to read into. This changes the AFS to only "mess up" the section of the array that would actually be written to by Muninn.
- Loading branch information
Showing
13 changed files
with
149 additions
and
35 deletions.
There are no files selected for viewing
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
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
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
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
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
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
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
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
53 changes: 53 additions & 0 deletions
53
...unity/io/src/test/java/org/neo4j/adversaries/pagecache/AdversarialReadPageCursorTest.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,53 @@ | ||
/* | ||
* Copyright (c) 2002-2018 "Neo Technology," | ||
* Network Engine for Objects in Lund AB [http://neotechnology.com] | ||
* | ||
* This file is part of Neo4j. | ||
* | ||
* Neo4j is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
package org.neo4j.adversaries.pagecache; | ||
|
||
import org.junit.Test; | ||
|
||
import java.util.concurrent.atomic.AtomicBoolean; | ||
|
||
import org.neo4j.io.pagecache.ByteArrayPageCursor; | ||
import org.neo4j.test.rule.PageCacheRule; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
|
||
public class AdversarialReadPageCursorTest | ||
{ | ||
@Test | ||
public void shouldNotMessUpUnrelatedSegmentOnReadBytes() throws Exception | ||
{ | ||
// Given | ||
byte[] buf = new byte[4]; | ||
byte[] page = new byte[]{7}; | ||
AdversarialReadPageCursor cursor = new AdversarialReadPageCursor( new ByteArrayPageCursor( page ), | ||
new PageCacheRule.AtomicBooleanInconsistentReadAdversary( new AtomicBoolean( true ) ) ); | ||
|
||
// When | ||
cursor.next( 0 ); | ||
cursor.getBytes( buf, buf.length - 1, 1 ); | ||
cursor.shouldRetry(); | ||
cursor.getBytes( buf, buf.length - 1, 1 ); | ||
|
||
// Then the range outside of buf.length-1, buf.length should be pristine | ||
assertEquals( 0, buf[0] ); | ||
assertEquals( 0, buf[1] ); | ||
assertEquals( 0, buf[2] ); | ||
} | ||
} |
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
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
60 changes: 60 additions & 0 deletions
60
community/io/src/test/java/org/neo4j/test/impl/ChannelOutputStreamTest.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,60 @@ | ||
/* | ||
* Copyright (c) 2002-2018 "Neo Technology," | ||
* Network Engine for Objects in Lund AB [http://neotechnology.com] | ||
* | ||
* This file is part of Neo4j. | ||
* | ||
* Neo4j is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
package org.neo4j.test.impl; | ||
|
||
import org.junit.Rule; | ||
import org.junit.Test; | ||
import org.junit.rules.TemporaryFolder; | ||
|
||
import java.io.File; | ||
import java.io.InputStream; | ||
import java.io.OutputStream; | ||
|
||
import org.neo4j.test.rule.fs.EphemeralFileSystemRule; | ||
import org.neo4j.test.rule.fs.FileSystemRule; | ||
|
||
public class ChannelOutputStreamTest | ||
{ | ||
@Rule | ||
public FileSystemRule fs = new EphemeralFileSystemRule(); | ||
|
||
@Rule | ||
public TemporaryFolder tmpDir = new TemporaryFolder(); | ||
|
||
@Test | ||
public void shouldStoreAByteAtBoundary() throws Exception | ||
{ | ||
File workFile = tmpDir.newFile(); | ||
fs.mkdirs( tmpDir.getRoot() ); | ||
OutputStream out = fs.openAsOutputStream( workFile, false ); | ||
|
||
// When I write a byte[] that is larger than the internal buffer in | ||
// ChannelOutputStream.. | ||
byte[] b = new byte[8097]; | ||
b[b.length - 1] = 7; | ||
out.write( b ); | ||
out.flush(); | ||
|
||
// Then it should get cleanly written and be readable | ||
InputStream in = fs.openAsInputStream( workFile ); | ||
in.skip( 8096 ); | ||
assert in.read() == 7; | ||
} | ||
} |
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