public class MockMongoDBServer extends Thread
Thread.State, Thread.UncaughtExceptionHandler
Modifier and Type | Field and Description |
---|---|
static byte[] |
EMPTY_BYTES
An empty Array of bytes.
|
protected int |
myClientConnected
Set to true when a client is connected.
|
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
Constructor and Description |
---|
MockMongoDBServer()
Creates a new MockMongoDBServer.
|
Modifier and Type | Method and Description |
---|---|
void |
clear()
Clears the requests received and replies to send.
|
void |
close()
Closes the server socket.
|
protected void |
close(Socket socket)
Closes the
Socket and logs any error. |
boolean |
disconnectClient()
Disconnects any active client..
|
InetSocketAddress |
getInetSocketAddress()
Returns the address for the server.
|
List<Reply> |
getReplies()
Returns the replies that will be returned after each message is received.
|
List<Message> |
getRequests()
Returns the requests that have been received.
|
protected void |
handleClient(Socket clientSocket)
Handles a single client connection.
|
boolean |
isRunning()
Returns if the server is running.
|
protected Header |
readHeader(BsonInputStream bin)
Receives a single message from the connection.
|
protected Message |
readMessage(Header header,
BsonInputStream bin)
Receives a single message from the connection.
|
void |
run()
Runs the server loop waiting for connections and servicing a single
client until it exits.
|
void |
setReplies(List<Reply> replies)
Sets the replies to return after each message is received.
|
void |
setReplies(Reply... replies)
Sets the replies to return after each message is received.
|
void |
setRunning(boolean running)
Controls if the server is running.
|
protected void |
sleep()
Yawn - go to slepp.
|
boolean |
waitForClient(long timeout)
Waits for a client to connect.
|
boolean |
waitForDisconnect(long timeout)
Waits for a client to disconnect.
|
boolean |
waitForRequest(int count,
long timeout)
Waits for a client request.
|
activeCount, checkAccess, clone, countStackFrames, currentThread, destroy, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, start, stop, stop, suspend, toString, yield
public static final byte[] EMPTY_BYTES
protected int myClientConnected
public MockMongoDBServer() throws IOException
IOException
- On a failure creating the server socket.public void clear()
public void close() throws IOException
IOException
- On a failure closing the server socket.public boolean disconnectClient()
public InetSocketAddress getInetSocketAddress()
public List<Reply> getReplies()
public List<Message> getRequests()
public boolean isRunning()
public void run()
public void setReplies(List<Reply> replies)
replies
- the replies to sendpublic void setReplies(Reply... replies)
replies
- the replies to sendpublic void setRunning(boolean running)
running
- the running to setpublic boolean waitForClient(long timeout)
timeout
- Time to wait (in milliseconds) for the disconnect.public boolean waitForDisconnect(long timeout)
timeout
- Time to wait (in milliseconds) for the disconnect.public boolean waitForRequest(int count, long timeout)
count
- The number of request to wait for.timeout
- Time to wait (in milliseconds) for the disconnect.protected void close(Socket socket)
socket
- The connection to close. Sockets do not implement
Closeable
in Java 6protected void handleClient(Socket clientSocket) throws IOException
clientSocket
- The socket to receive messages from.IOException
- On a connection error.protected Header readHeader(BsonInputStream bin) throws IOException
bin
- The stream to read the message.Message
received.IOException
- On an error receiving the message.protected Message readMessage(Header header, BsonInputStream bin) throws IOException
header
- The read message header.bin
- The stream to read the message.Message
received.IOException
- On an error receiving the message.protected void sleep()
Copyright © 2011–2014 Allanbank Consulting, Inc.. All rights reserved.