[TEST] Close input stream in test to not upset windows

This commit is contained in:
Simon Willnauer 2014-09-06 22:07:01 +02:00
parent 13e3a5e99c
commit 36f9d39205
1 changed files with 16 additions and 15 deletions

View File

@ -30,23 +30,22 @@ import org.junit.Test;
import java.io.*;
import java.util.Arrays;
import java.util.Random;
public class BlobStoreTest extends ElasticsearchTestCase {
@Test
public void testWriteRead() throws IOException {
BlobContainer store = newBlobContainer();
final BlobStore store = newBlobStore();
final BlobContainer container = store.blobContainer(new BlobPath());
int length = randomIntBetween(10, scaledRandomIntBetween(1024, 1 << 16));
byte[] data = new byte[length];
for (int i = 0; i < data.length; i++) {
data[i] = (byte) randomInt();
}
try (OutputStream stream = store.createOutput("foobar")) {
try (OutputStream stream = container.createOutput("foobar")) {
stream.write(data);
}
InputStream stream = store.openInput("foobar");
try (InputStream stream = container.openInput("foobar")) {
BytesRef target = new BytesRef();
while (target.length < data.length) {
byte[] buffer = new byte[scaledRandomIntBetween(1, data.length - target.length)];
@ -57,11 +56,13 @@ public class BlobStoreTest extends ElasticsearchTestCase {
assertEquals(data.length, target.length);
assertArrayEquals(data, Arrays.copyOfRange(target.bytes, target.offset, target.length));
}
store.close();
}
protected BlobContainer newBlobContainer() {
protected BlobStore newBlobStore() {
File tempDir = newTempDir(LifecycleScope.TEST);
Settings settings = randomBoolean() ? ImmutableSettings.EMPTY : ImmutableSettings.builder().put("buffer_size", new ByteSizeValue(randomIntBetween(1, 100), ByteSizeUnit.KB)).build();
FsBlobStore store = new FsBlobStore(settings, tempDir);
return store.blobContainer(new BlobPath());
return store;
}
}