public final class PseudoCvsServer
extends java.lang.Object
implements java.lang.Runnable
Typical server usage in unit test sequence:
InputStream in = getClass().getResourceAsStream("..."); PseudoCvsServer cvss = new PseudoCvsServer(in); new Thread(cvss).start(); String cvsRoot = cvss.getCvsRoot(); <client operations> cvss.stop(); // check test failure <tested client asserts>
Fake input and output streams can be on Unix systems catched using nc program. To catch command line cvs:
nc -l -p $3000 | tee $requests.logand
cvs -d :pserver:$ano@127.0.0.1:$3000/$cvs -z0 $whateEverCommand
nc $cvs.netbeans.org $2401 | tee $reponses.log
Constructor and Description |
---|
PseudoCvsServer(java.io.InputStream in)
Creates new server that replies with given data.
|
PseudoCvsServer(java.lang.String name) |
Modifier and Type | Method and Description |
---|---|
java.lang.String |
getCvsRoot()
Utility method returning typical CVSRoot sutable for
local CVSClient testing.
|
int |
getPort()
returns port that accepts client requests.
|
void |
ignoreProbe()
Enters ignore very first connect mode (connection probe).
|
void |
logRequests(java.io.OutputStream out)
Logs server input intu specified stream.
|
void |
run()
Entry point, starts listening at port and sends out
predefined replies.
|
void |
simulateNetworkFailure(int write,
int read)
Enters hard network failure simulation mode, silentry
dropping down connection after specified number of in/outgoing bytes.
|
void |
simulateServerOverload(int write,
int read)
Enters server overload simulation mode.
|
void |
simulateSlowNetwork(int write,
int read) |
void |
stop()
Stops server and optionaly rethrows internal server exception if any.
|
java.lang.String |
toString()
For diagnostics purpoes only.
|
public PseudoCvsServer(java.lang.String name) throws java.io.IOException
java.io.IOException
public PseudoCvsServer(java.io.InputStream in) throws java.io.IOException
in
- input stream that is consumend and closed
once server runnable terminates.java.io.IOException
- if cannot create server socketpublic int getPort()
public java.lang.String getCvsRoot()
":pserver:anoncvs@127.0.0.1:" + getPort() + "/cvs"
public void simulateNetworkFailure(int write, int read)
write
- specifies number of bytes send before
closing socket output stream. -1 for unlimited.read
- specifies number of bytes received before
closing socket input stream. -1 for unlimited.public void simulateServerOverload(int write, int read)
write
- specifies number of bytes send before
shuting down socket output stream. -1 for unlimited.read
- specifies number of bytes received before
shuting down socket input stream. -1 for unlimited.public void simulateSlowNetwork(int write, int read)
public void ignoreProbe()
public void logRequests(java.io.OutputStream out)
out
- log stream. The stream is closed on server termination.public void run()
run
in interface java.lang.Runnable
public void stop() throws java.lang.Exception
java.lang.Exception
public java.lang.String toString()
toString
in class java.lang.Object