Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
dCache
dcache-cta
Commits
65ef5d33
Commit
65ef5d33
authored
Nov 08, 2021
by
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
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
src/main/java/org/dcache/nearline/cta/xrootd/DataServerHandler.java
View file @
65ef5d33
...
...
@@ -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"
);
}
...
...
src/test/java/org/dcache/nearline/cta/xrootd/DataServerHandlerTest.java
View file @
65ef5d33
...
...
@@ -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
);
}
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment