Skip to content

Commit

Permalink
Use a less resource-intensive source of random data
Browse files Browse the repository at this point in the history
  • Loading branch information
barmintor committed May 9, 2013
1 parent 2912afd commit 85dc79e
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 8 deletions.
Expand Up @@ -25,6 +25,9 @@
import org.mockito.stubbing.Answer;

public abstract class TestHelpers {

private static final SecureRandom GARBAGE_GENERATOR = new SecureRandom("G4RbAG3".getBytes());

public static Node getContentNodeMock(final int size) {
return getContentNodeMock(randomData(size));
}
Expand Down Expand Up @@ -116,7 +119,7 @@ public static PropertyIterator getPropertyIterator(final int numValues,

public static byte[] randomData(final int byteLength) {
final byte[] bytes = new byte[byteLength];
new SecureRandom().nextBytes(bytes);
GARBAGE_GENERATOR.nextBytes(bytes);
return bytes;
}
}
Expand Up @@ -7,6 +7,7 @@
import java.io.IOException;
import java.security.SecureRandom;

import org.fcrepo.utils.TestHelpers;
import org.infinispan.container.entries.InternalCacheEntry;
import org.infinispan.loaders.CacheLoaderException;
import org.infinispan.loaders.CacheStore;
Expand Down Expand Up @@ -44,7 +45,7 @@ public void testRead() throws IOException {
@Test
public void testBufferedRead() throws IOException, CacheLoaderException {
InternalCacheEntry mockEntry = mock(InternalCacheEntry.class);
byte [] data = SecureRandom.getSeed(DATA_SIZE);
byte[] data = TestHelpers.randomData(DATA_SIZE);
when(mockEntry.getValue()).thenReturn(data);
when(mockStore.load(anyString())).thenReturn(mockEntry).thenReturn(mockEntry).thenReturn(null);
int partition = 234;
Expand All @@ -67,7 +68,7 @@ public void testBufferedRead() throws IOException, CacheLoaderException {

@Test
public void testAvailable() throws IOException, CacheLoaderException {
byte [] data = SecureRandom.getSeed(DATA_SIZE);
byte[] data = TestHelpers.randomData(DATA_SIZE);
when(mockEntry.getValue()).thenReturn(data);
when(mockStore.load(mockFirstChunk)).thenReturn(mockEntry);
assertEquals(0, testObj.available());
Expand All @@ -86,7 +87,7 @@ public void testAvailable() throws IOException, CacheLoaderException {
@Test
public void testSkip() throws IOException, CacheLoaderException {
long expected = (DATA_SIZE - 1);
byte [] data = SecureRandom.getSeed(DATA_SIZE);
byte[] data = TestHelpers.randomData(DATA_SIZE);
when(mockEntry.getValue()).thenReturn(data);
when(mockStore.load(mockFirstChunk)).thenReturn(mockEntry);
long actual = testObj.skip(expected);
Expand All @@ -101,7 +102,7 @@ public void testSkip() throws IOException, CacheLoaderException {
@Test
public void testSkipMultipleBuffers() throws IOException, CacheLoaderException {
InternalCacheEntry mockEntry = mock(InternalCacheEntry.class);
byte [] data = SecureRandom.getSeed(DATA_SIZE);
byte[] data = TestHelpers.randomData(DATA_SIZE);
when(mockEntry.getValue()).thenReturn(data);
when(mockStore.load(anyString())).thenReturn(mockEntry).thenReturn(mockEntry).thenReturn(null);

Expand Down
Expand Up @@ -6,6 +6,7 @@
import java.io.IOException;
import java.security.SecureRandom;

import org.fcrepo.utils.TestHelpers;
import org.infinispan.container.entries.InternalCacheEntry;
import org.infinispan.loaders.CacheLoaderException;
import org.infinispan.loaders.CacheStore;
Expand All @@ -15,7 +16,7 @@
public class StoreChunkOutputStreamTest {

private static final int DATA_SIZE = 1024;

private StoreChunkOutputStream testObj;

private CacheStore mockStore;
Expand All @@ -34,7 +35,7 @@ public void setUp() {

@Test
public void testWritingMultipleChunks() throws IOException, CacheLoaderException {
byte[] data = SecureRandom.getSeed(DATA_SIZE);
byte[] data = TestHelpers.randomData(DATA_SIZE);
for (int i=0; i< 1025; i++) {
testObj.write(data);
}
Expand All @@ -45,7 +46,7 @@ public void testWritingMultipleChunks() throws IOException, CacheLoaderException

@Test
public void testWritingMultipleChunksOnVersionedKey() throws IOException, CacheLoaderException {
byte[] data = SecureRandom.getSeed(DATA_SIZE);
byte[] data = TestHelpers.randomData(DATA_SIZE);
when(mockStore.load(mockKey + "-0")).thenReturn(mockEntry);
for (int i=0; i< 1025; i++) {
testObj.write(data);
Expand Down

0 comments on commit 85dc79e

Please sign in to comment.