use of io.crate.blob.transfer.PutHeadChunkRunnable in project crate by crate.
the class BlobHeadRequestHandlerTests method testPutHeadChunkRunnableFileDoesntGrow.
@Test
public void testPutHeadChunkRunnableFileDoesntGrow() throws Exception {
// this test is rather slow, tune wait time in PutHeadChunkRunnable?
expectedException.expect(HeadChunkFileTooSmallException.class);
File file = File.createTempFile("test", "");
File notExisting = new File("./does/not/exist");
try (final FileOutputStream outputStream = new FileOutputStream(file)) {
outputStream.write(new byte[] { 0x65 });
}
UUID transferId = UUID.randomUUID();
BlobTransferTarget transferTarget = mock(BlobTransferTarget.class);
DiscoveryNode node1 = new DiscoveryNode("node1", buildNewFakeTransportAddress(), Version.CURRENT);
DigestBlob digestBlob = mock(DigestBlob.class);
when(digestBlob.file()).thenReturn(notExisting);
when(digestBlob.getContainerFile()).thenReturn(file);
PutHeadChunkRunnable runnable = new PutHeadChunkRunnable(digestBlob, 5, transportService, transferTarget, node1, transferId);
runnable.run();
verify(digestBlob).getContainerFile();
}
use of io.crate.blob.transfer.PutHeadChunkRunnable in project crate by crate.
the class BlobHeadRequestHandlerTests method testPutHeadChunkRunnableFileGrowth.
@Test
public void testPutHeadChunkRunnableFileGrowth() throws Exception {
File file = File.createTempFile("test", "");
try (final FileOutputStream outputStream = new FileOutputStream(file)) {
outputStream.write(new byte[] { 0x65 });
UUID transferId = UUID.randomUUID();
BlobTransferTarget blobTransferTarget = mock(BlobTransferTarget.class);
DigestBlob digestBlob = mock(DigestBlob.class);
when(digestBlob.file()).thenReturn(file);
ScheduledExecutorService scheduledExecutor = Executors.newSingleThreadScheduledExecutor(EsExecutors.daemonThreadFactory("blob-head"));
try {
scheduledExecutor.schedule(new Runnable() {
@Override
public void run() {
try {
outputStream.write(new byte[] { 0x66, 0x67, 0x68, 0x69 });
} catch (IOException ex) {
// pass
}
}
}, 800, TimeUnit.MILLISECONDS);
DiscoveryNode node1 = new DiscoveryNode("node1", buildNewFakeTransportAddress(), Version.CURRENT);
PutHeadChunkRunnable runnable = new PutHeadChunkRunnable(digestBlob, 5, transportService, blobTransferTarget, node1, transferId);
runnable.run();
verify(blobTransferTarget).putHeadChunkTransferFinished(transferId);
} finally {
scheduledExecutor.awaitTermination(1, TimeUnit.SECONDS);
scheduledExecutor.shutdownNow();
}
}
}
Aggregations