Commit 65ef5d33 authored by Tigran Mkrtchyan's avatar Tigran Mkrtchyan
Browse files

xroot: add check and test for data file open modes

parent 40d10cdc
Pipeline #12366 passed with stages
in 2 minutes and 58 seconds
......@@ -189,12 +189,20 @@ public class DataServerHandler extends XrootdRequestHandler {
RandomAccessFile raf;
if (msg.isReadWrite() || msg.isNew() || msg.isDelete()) {
if (!(r instanceof StageRequest)) {
throw new XrootdException(kXR_ArgInvalid,
"An attempt to open-for-read for stage requests");
}
LOGGER.info("Opening {} for writing", file);
raf = new RandomAccessFile(file, "rw");
if (msg.isDelete()) {
raf.setLength(0);
}
} else {
if (!(r instanceof FlushRequest)) {
throw new XrootdException(kXR_ArgInvalid,
"An attempt to open-for-write for flush requests");
}
LOGGER.info("Opening {} for reading.", file);
raf = new RandomAccessFile(file, "r");
}
......
......@@ -101,10 +101,49 @@ public class DataServerHandlerTest {
var buf = new ByteBufBuilder()
.withShort(1) // stream id
.withShort(XrootdProtocol.kXR_open)
.withZeros(16) // padding
.withShort(0)
.withShort(XrootdProtocol.kXR_open_read)
.withZeros(12) // padding
.withString("0000C9B4E3768770452E8B1B8E0232584872", UTF_8)
.build();
OpenRequest msg = new OpenRequest(buf);
handler.doOnOpen(ctx, msg);
}
@Test(expected = XrootdException.class)
public void testOpenForWriteFlushRequest() throws XrootdException, IOException {
mockedFlushRequest();
var buf = new ByteBufBuilder()
.withShort(1) // stream id
.withShort(XrootdProtocol.kXR_open)
.withShort(0)
.withShort(XrootdProtocol.kXR_delete | XrootdProtocol.kXR_new
| XrootdProtocol.kXR_writable)
.withZeros(12) // padding
.withString("0000C9B4E3768770452E8B1B8E0232584872", UTF_8)
.build();
OpenRequest msg = new OpenRequest(buf);
handler.doOnOpen(ctx, msg);
}
@Test(expected = XrootdException.class)
public void testOpenForReadForStageRequest() throws XrootdException, IOException {
mockedStageRequest();
var buf = new ByteBufBuilder()
.withShort(1) // stream id
.withShort(XrootdProtocol.kXR_open)
.withShort(0)
.withShort(XrootdProtocol.kXR_open_read)
.withZeros(12) // padding
.withString("0000C9B4E3768770452E8B1B8E0232584872", UTF_8)
.build();
OpenRequest msg = new OpenRequest(buf);
......@@ -120,10 +159,10 @@ public class DataServerHandlerTest {
var buf = new ByteBufBuilder()
.withShort(1) // stream id
.withShort(XrootdProtocol.kXR_open)
.withZeros(16) // padding
.withString("0000C9B4E3768770452E8B1B8E0232584872", UTF_8)
.withShort(0)
.withShort(XrootdProtocol.kXR_open_read)
.withZeros(12) // padding
.withString("0000C9B4E3768770452E8B1B8E0232584872", UTF_8)
.build();
new File(stageRequest.getReplicaUri()).delete();
......@@ -179,7 +218,8 @@ public class DataServerHandlerTest {
}
@Test
public void testStatByOpenFileStage() throws XrootdException, IOException, InterruptedException {
public void testStatByOpenFileStage()
throws XrootdException, IOException, InterruptedException {
var flushRequest = mockedFlushRequest();
......@@ -381,7 +421,8 @@ public class DataServerHandlerTest {
var msg = new QueryRequest(buf);
handler.doOnQuery(ctx, msg);
var expectedUri = Set.of(URI.create("cta://test/0000C9B4E3768770452E8B1B8E0232584872?archiveid=31415926"));
var expectedUri = Set.of(
URI.create("cta://test/0000C9B4E3768770452E8B1B8E0232584872?archiveid=31415926"));
verify(stageRequest).completed(expectedUri);
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment