Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
dCache
nfs4j
Commits
b26f677f
Commit
b26f677f
authored
Dec 20, 2011
by
Tigran Mkrtchyan
☕
Browse files
junit: add create session tests
parent
a4286b13
Changes
3
Hide whitespace changes
Inline
Side-by-side
test/org/dcache/chimera/nfs/v4/AssertNFS.java
0 → 100644
View file @
b26f677f
/*
* This library is free software; you can redistribute it and/or modify
* it under the terms of the GNU Library General Public License as
* published by the Free Software Foundation; either version 2 of the
* License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this program (see the file COPYING.LIB for more
* details); if not, write to the Free Software Foundation, Inc.,
* 675 Mass Ave, Cambridge, MA 02139, USA.
*/
package
org.dcache.chimera.nfs.v4
;
import
junit.framework.AssertionFailedError
;
import
org.dcache.chimera.nfs.ChimeraNFSException
;
import
org.dcache.chimera.nfs.nfsstat
;
import
org.dcache.chimera.nfs.v4.xdr.nfs_resop4
;
public
class
AssertNFS
{
public
static
void
assertNFS
(
AbstractNFSv4Operation
op
,
CompoundContext
context
,
nfs_resop4
result
,
int
expectedStatus
)
throws
Exception
{
try
{
op
.
process
(
context
,
result
);
assertNFSStatus
(
expectedStatus
,
result
.
getStatus
());
}
catch
(
ChimeraNFSException
e
)
{
assertNFSStatus
(
expectedStatus
,
e
.
getStatus
());
}
}
/**
*
* @param msg
* @param expected
* @param actual
*/
public
static
void
assertNFSStatus
(
String
msg
,
int
expected
,
int
actual
)
{
if
(
expected
!=
actual
)
{
String
message
=
String
.
format
(
"%s: expected:<%s> but was:<%s>"
,
msg
,
nfsstat
.
toString
(
expected
),
nfsstat
.
toString
(
actual
));
throw
new
AssertionFailedError
(
message
);
}
}
/**
*
* @param expected
* @param actual
*/
public
static
void
assertNFSStatus
(
int
expected
,
int
actual
)
{
if
(
expected
!=
actual
)
{
String
message
=
String
.
format
(
"expected:<%s> but was:<%s>"
,
nfsstat
.
toString
(
expected
),
nfsstat
.
toString
(
actual
));
throw
new
AssertionFailedError
(
message
);
}
}
}
test/org/dcache/chimera/nfs/v4/CompoundContextBuilder.java
0 → 100644
View file @
b26f677f
/*
* This library is free software; you can redistribute it and/or modify
* it under the terms of the GNU Library General Public License as
* published by the Free Software Foundation; either version 2 of the
* License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this program (see the file COPYING.LIB for more
* details); if not, write to the Free Software Foundation, Inc.,
* 675 Mass Ave, Cambridge, MA 02139, USA.
*/
package
org.dcache.chimera.nfs.v4
;
import
java.io.IOException
;
import
java.net.InetAddress
;
import
java.net.InetSocketAddress
;
import
javax.security.auth.Subject
;
import
org.dcache.chimera.nfs.ExportFile
;
import
org.dcache.chimera.nfs.vfs.VirtualFileSystem
;
import
org.dcache.chimera.posix.AclHandler
;
import
org.dcache.xdr.*
;
public
class
CompoundContextBuilder
{
private
final
static
XdrTransport
transport
=
new
XdrTransport
()
{
@Override
public
void
send
(
Xdr
xdr
)
throws
IOException
{
throw
new
UnsupportedOperationException
(
"Not supported yet."
);
}
@Override
public
ReplyQueue
<
Integer
,
RpcReply
>
getReplyQueue
()
{
throw
new
UnsupportedOperationException
(
"Not supported yet."
);
}
@Override
public
InetSocketAddress
getLocalSocketAddress
()
{
return
new
InetSocketAddress
(
InetAddress
.
getLoopbackAddress
(),
2049
);
}
@Override
public
InetSocketAddress
getRemoteSocketAddress
()
{
return
new
InetSocketAddress
(
InetAddress
.
getLoopbackAddress
(),
7777
);
}
@Override
public
XdrTransport
getPeerTransport
()
{
throw
new
UnsupportedOperationException
(
"Not supported yet."
);
}
};
private
final
static
RpcAuth
auth
=
new
RpcAuth
()
{
@Override
public
int
type
()
{
return
RpcAuthType
.
UNIX
;
}
@Override
public
RpcAuthVerifier
getVerifier
()
{
throw
new
UnsupportedOperationException
(
"Not supported yet."
);
}
@Override
public
Subject
getSubject
()
{
return
new
Subject
();
}
@Override
public
void
xdrDecode
(
XdrDecodingStream
xdr
)
throws
OncRpcException
,
IOException
{
throw
new
UnsupportedOperationException
(
"Not supported yet."
);
}
@Override
public
void
xdrEncode
(
XdrEncodingStream
xdr
)
throws
OncRpcException
,
IOException
{
throw
new
UnsupportedOperationException
(
"Not supported yet."
);
}
};
private
RpcCall
call
=
new
RpcCall
(
100003
,
4
,
auth
,
transport
);
private
int
minorversion
=
0
;
private
VirtualFileSystem
fs
=
null
;
private
NFSv4StateHandler
stateHandler
=
null
;
private
NFSv41DeviceManager
deviceManager
=
null
;
private
AclHandler
aclHandler
=
null
;
private
NfsIdMapping
idMapping
=
null
;
private
ExportFile
exportFile
=
null
;
private
int
opCount
=
0
;
public
CompoundContextBuilder
withAclHandler
(
AclHandler
aclHandler
)
{
this
.
aclHandler
=
aclHandler
;
return
this
;
}
public
CompoundContextBuilder
withCall
(
RpcCall
call
)
{
this
.
call
=
call
;
return
this
;
}
public
CompoundContextBuilder
withDeviceManager
(
NFSv41DeviceManager
deviceManager
)
{
this
.
deviceManager
=
deviceManager
;
return
this
;
}
public
CompoundContextBuilder
withExportFile
(
ExportFile
exportFile
)
{
this
.
exportFile
=
exportFile
;
return
this
;
}
public
CompoundContextBuilder
withFs
(
VirtualFileSystem
fs
)
{
this
.
fs
=
fs
;
return
this
;
}
public
CompoundContextBuilder
withIdMapping
(
NfsIdMapping
idMapping
)
{
this
.
idMapping
=
idMapping
;
return
this
;
}
public
CompoundContextBuilder
withMinorversion
(
int
minorversion
)
{
this
.
minorversion
=
minorversion
;
return
this
;
}
public
CompoundContextBuilder
withOpCount
(
int
opCount
)
{
this
.
opCount
=
opCount
;
return
this
;
}
public
CompoundContextBuilder
withStateHandler
(
NFSv4StateHandler
stateHandler
)
{
this
.
stateHandler
=
stateHandler
;
return
this
;
}
public
CompoundContext
build
()
{
return
new
CompoundContext
(
minorversion
,
fs
,
stateHandler
,
deviceManager
,
aclHandler
,
call
,
idMapping
,
exportFile
,
opCount
);
}
}
test/org/dcache/chimera/nfs/v4/OperationCREATE_SESSIONTest.java
0 → 100644
View file @
b26f677f
/*
* This library is free software; you can redistribute it and/or modify
* it under the terms of the GNU Library General Public License as
* published by the Free Software Foundation; either version 2 of the
* License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this program (see the file COPYING.LIB for more
* details); if not, write to the Free Software Foundation, Inc.,
* 675 Mass Ave, Cambridge, MA 02139, USA.
*/
package
org.dcache.chimera.nfs.v4
;
import
java.util.UUID
;
import
org.dcache.chimera.nfs.nfsstat
;
import
org.dcache.chimera.nfs.v4.client.CreateSessionStub
;
import
org.dcache.chimera.nfs.v4.client.ExchangeIDStub
;
import
org.dcache.chimera.nfs.v4.xdr.*
;
import
org.junit.Before
;
import
org.junit.Test
;
public
class
OperationCREATE_SESSIONTest
{
private
NFSv4StateHandler
stateHandler
;
private
final
String
domain
=
"nairi.desy.de"
;
private
final
String
name
=
"dCache.ORG java based client"
;
private
String
clientId
;
@Before
public
void
setUp
()
{
stateHandler
=
new
NFSv4StateHandler
();
clientId
=
UUID
.
randomUUID
().
toString
();
}
@Test
public
void
testCreateSession
()
throws
Exception
{
CompoundContext
context
;
nfs_resop4
result
;
nfs_argop4
exchangeid_args
=
ExchangeIDStub
.
normal
(
domain
,
name
,
clientId
,
0
,
state_protect_how4
.
SP4_NONE
);
OperationEXCHANGE_ID
EXCHANGE_ID
=
new
OperationEXCHANGE_ID
(
exchangeid_args
,
0
);
result
=
nfs_resop4
.
resopFor
(
nfs_opnum4
.
OP_EXCHANGE_ID
);
context
=
new
CompoundContextBuilder
()
.
withStateHandler
(
stateHandler
)
.
withOpCount
(
1
)
.
build
();
AssertNFS
.
assertNFS
(
EXCHANGE_ID
,
context
,
result
,
nfsstat
.
NFS_OK
);
nfs_argop4
cretaesession_args
=
CreateSessionStub
.
standard
(
result
.
opexchange_id
.
eir_resok4
.
eir_clientid
,
result
.
opexchange_id
.
eir_resok4
.
eir_sequenceid
);
OperationCREATE_SESSION
CREATE_SESSION
=
new
OperationCREATE_SESSION
(
cretaesession_args
);
result
=
nfs_resop4
.
resopFor
(
nfs_opnum4
.
OP_CREATE_SESSION
);
context
=
new
CompoundContextBuilder
()
.
withStateHandler
(
stateHandler
)
.
withOpCount
(
1
)
.
build
();
AssertNFS
.
assertNFS
(
CREATE_SESSION
,
context
,
result
,
nfsstat
.
NFS_OK
);
}
@Test
public
void
testCreateSessionNoClient
()
throws
Exception
{
CompoundContext
context
;
nfs_resop4
result
;
nfs_argop4
cretaesession_args
=
CreateSessionStub
.
standard
(
new
clientid4
(
new
uint64_t
(
0
)),
new
sequenceid4
(
new
uint32_t
(
0
)));
OperationCREATE_SESSION
CREATE_SESSION
=
new
OperationCREATE_SESSION
(
cretaesession_args
);
result
=
nfs_resop4
.
resopFor
(
nfs_opnum4
.
OP_CREATE_SESSION
);
context
=
new
CompoundContextBuilder
()
.
withStateHandler
(
stateHandler
)
.
withOpCount
(
1
)
.
build
();
AssertNFS
.
assertNFS
(
CREATE_SESSION
,
context
,
result
,
nfsstat
.
NFSERR_STALE_CLIENTID
);
}
@Test
public
void
testCreateSessionMisordered
()
throws
Exception
{
CompoundContext
context
;
nfs_resop4
result
;
nfs_argop4
exchangeid_args
=
ExchangeIDStub
.
normal
(
domain
,
name
,
clientId
,
0
,
state_protect_how4
.
SP4_NONE
);
OperationEXCHANGE_ID
EXCHANGE_ID
=
new
OperationEXCHANGE_ID
(
exchangeid_args
,
0
);
result
=
nfs_resop4
.
resopFor
(
nfs_opnum4
.
OP_EXCHANGE_ID
);
context
=
new
CompoundContextBuilder
().
withStateHandler
(
stateHandler
).
withOpCount
(
1
).
build
();
AssertNFS
.
assertNFS
(
EXCHANGE_ID
,
context
,
result
,
nfsstat
.
NFS_OK
);
sequenceid4
badSequence
=
new
sequenceid4
(
new
uint32_t
(
result
.
opexchange_id
.
eir_resok4
.
eir_sequenceid
.
value
.
value
+
1
)
);
nfs_argop4
cretaesession_args
=
CreateSessionStub
.
standard
(
result
.
opexchange_id
.
eir_resok4
.
eir_clientid
,
badSequence
);
OperationCREATE_SESSION
CREATE_SESSION
=
new
OperationCREATE_SESSION
(
cretaesession_args
);
result
=
nfs_resop4
.
resopFor
(
nfs_opnum4
.
OP_CREATE_SESSION
);
context
=
new
CompoundContextBuilder
()
.
withStateHandler
(
stateHandler
)
.
withOpCount
(
1
)
.
build
();
AssertNFS
.
assertNFS
(
CREATE_SESSION
,
context
,
result
,
nfsstat
.
NFSERR_SEQ_MISORDERED
);
}
}
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new 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