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

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

parent abfdae85
No related branches found
No related tags found
1 merge request!40SSDM-13578 : 2PT : Database and V3 Implementation - include the new AFS "free"...
......@@ -15,6 +15,7 @@ import java.nio.file.StandardOpenOption;
import java.security.MessageDigest;
import java.time.Duration;
import java.util.AbstractMap;
import java.util.Arrays;
import java.util.Base64;
import java.util.HashMap;
import java.util.List;
......@@ -322,7 +323,7 @@ public final class AfsClient implements PublicAPI, ClientAPI
{
final ByteBuffer byteBuffer = ByteBuffer.allocate(DEFAULT_PACKAGE_SIZE_IN_BYTES);
fileChannel.read(byteBuffer, offset, byteBuffer,
new ChannelReadCompletionHandler(owner, destination, byteBuffer, offset, latch, hasError));
new ChannelReadCompletionHandler(owner, destination, offset, latch, hasError));
offset += DEFAULT_PACKAGE_SIZE_IN_BYTES;
}
......@@ -543,8 +544,6 @@ public final class AfsClient implements PublicAPI, ClientAPI
private class ChannelReadCompletionHandler implements CompletionHandler<Integer, ByteBuffer>
{
private final ByteBuffer byteBuffer;
private final @NonNull String owner;
private final @NonNull String destination;
......@@ -555,11 +554,9 @@ public final class AfsClient implements PublicAPI, ClientAPI
private final Long offset;
public ChannelReadCompletionHandler(final @NonNull String owner, final @NonNull String destination, final ByteBuffer byteBuffer,
final Long offset, final CountDownLatch latch,
final AtomicBoolean hasError)
public ChannelReadCompletionHandler(final @NonNull String owner, final @NonNull String destination, final Long offset,
final CountDownLatch latch, final AtomicBoolean hasError)
{
this.byteBuffer = byteBuffer;
this.owner = owner;
this.destination = destination;
this.offset = offset;
......@@ -570,7 +567,8 @@ public final class AfsClient implements PublicAPI, ClientAPI
@Override
public void completed(final Integer result, final ByteBuffer attachment)
{
final byte[] data = byteBuffer.array();
final byte[] fullBuffer = attachment.array();
final byte[] data = result < fullBuffer.length ? Arrays.copyOf(fullBuffer, result) : fullBuffer;
try
{
final Boolean writeSuccessful = write(owner, destination, this.offset, data, getMD5(data));
......
......@@ -195,6 +195,17 @@ public abstract class BaseApiClientTest
assertArrayEquals(DATA, testDataFile);
}
@Test
public void resumeWrite_zeroOffset_createsFile() throws Exception
{
login();
final Boolean result = afsClient.resumeWrite(owner, FILE_B, Path.of(IOUtils.getPath(testDataRoot, FILE_A)), 0L);
assertTrue(result);
assertFilesEqual(IOUtils.getPath(testDataRoot, FILE_A), FILE_B);
}
@Test
public void delete_fileIsGone() throws Exception
{
......
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