Skip to content
Snippets Groups Projects
Commit bacdf446 authored by vkovtun's avatar vkovtun
Browse files

SSDM-13579: Added new test BaseApiClientTest.resumeWrite_nonZeroOffset_doesNotCreateFile().

parent 9753dc70
No related branches found
No related tags found
1 merge request!40SSDM-13578 : 2PT : Database and V3 Implementation - include the new AFS "free"...
......@@ -316,18 +316,23 @@ public final class AfsClient implements PublicAPI, ClientAPI
try (final AsynchronousFileChannel fileChannel = AsynchronousFileChannel.open(source, StandardOpenOption.READ))
{
final CountDownLatch latch = new CountDownLatch((int) ((sourceFileSize - offset - 1) / DEFAULT_PACKAGE_SIZE_IN_BYTES) + 1);
final long remainingFileSize = sourceFileSize - offset;
final AtomicBoolean hasError = new AtomicBoolean(false);
while (offset < sourceFileSize)
if (remainingFileSize > 0)
{
final ByteBuffer byteBuffer = ByteBuffer.allocate(DEFAULT_PACKAGE_SIZE_IN_BYTES);
fileChannel.read(byteBuffer, offset, byteBuffer,
new ChannelReadCompletionHandler(owner, destination, offset, latch, hasError));
offset += DEFAULT_PACKAGE_SIZE_IN_BYTES;
}
final CountDownLatch latch = new CountDownLatch((int) ((remainingFileSize - 1) / DEFAULT_PACKAGE_SIZE_IN_BYTES) + 1);
latch.await();
while (offset < sourceFileSize)
{
final ByteBuffer byteBuffer = ByteBuffer.allocate(DEFAULT_PACKAGE_SIZE_IN_BYTES);
fileChannel.read(byteBuffer, offset, byteBuffer,
new ChannelReadCompletionHandler(owner, destination, offset, latch, hasError));
offset += DEFAULT_PACKAGE_SIZE_IN_BYTES;
}
latch.await();
}
return !hasError.get();
} catch (final Exception e)
......
......@@ -204,6 +204,20 @@ public abstract class BaseApiClientTest
assertTrue(result);
assertFilesEqual(IOUtils.getPath(testDataRoot, FILE_A), FILE_B);
Path.of(FILE_B).toFile().delete();
}
@Test
public void resumeWrite_nonZeroOffset_doesNotCreateFile() throws Exception
{
login();
final Long offset = 65L;
final Boolean result = afsClient.resumeWrite(owner, FILE_B, Path.of(IOUtils.getPath(testDataRoot, FILE_A)), offset);
assertTrue(result);
assertFalse(Path.of(FILE_B).toFile().exists());
}
@Test
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment