|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.otfeed.support.mock.MockStreamerFactory
public class MockStreamerFactory
Mock streaming layer for offline testing.
This object facilitates offline testing of object marshalling code by returning a pre-recorded sequence of frames. Use this object to substitutestreamerFactory
of OTConnectionFactory
.
IMPORTANT: set heartbeatInterval
property of OTConnectionListener
to reasonably
large value to make sure that heartbeat frames are not
sent to the streamer layer. Otherwise, programs that
MockStreamerFactory
executes may be confused by
receiving a heartbeat packet.
IMPORTANT: recorded packets must contain correct requestId. Otherwise
they will be silently dropped. Request id starts with zero (login request)
and is incremented for every command prepared (event if not submitted).
Thus, first request will have id of one, second - id of two, etc.
Practically, its simpler to restrict testing to just a single command
and then destroy the connection. This way, all frames for a command
to be tested must have request id of 1.
Next, build a list of operations that will be the "program"
for the streamer. Assign this list to the opList
property of MockStreamerFactory
.
Example program may look like this:
// EXPECT ANY (will be login request frame) mockStreamerFactory.getOpList().add(MockStreamerFactory.expectAny()); // SEND "login OK" response mockStreamerFactory.getOpList().add(MockStreamerFactory.sendLoginOK()); // WAIT for any buffer mockStreamerFactory.getOpList().add(MockStreamerFactory.expectAny()); // No more elements in the list: streamer will emulate // disconnect from the server (read error).
Nested Class Summary | |
---|---|
static interface |
MockStreamerFactory.Op
|
Constructor Summary | |
---|---|
MockStreamerFactory()
Creates new mock streamer. |
Method Summary | |
---|---|
IStreamer |
connect(java.lang.String host,
int port)
Creates a connection (synchronously). |
static MockStreamerFactory.Op |
expectAny()
Creates an operation of "EXPECT ANY BUFFER" type. |
static MockStreamerFactory.Op |
expectBuffer(java.nio.ByteBuffer e)
Creates an operation of "EXPECT A BUFFER" type. |
IFormat<java.nio.ByteBuffer> |
getFormat()
Format to use when parsing ByteBuffer s. |
java.lang.String |
getId()
Identification string. |
java.util.List<MockStreamerFactory.Op> |
getOpList()
List of operations that drive the mock streamer. |
boolean |
getTrace()
Trace flag makes streamer print all frames to screen. |
static java.nio.ByteBuffer |
parse(java.lang.String bufferString)
Helper: creates a ByteBuffer from
its hex-dump String representation. |
static java.nio.ByteBuffer |
parseResource(java.lang.String resourceName)
Helper: creates a ByteBuffer by parsing
a resource file. |
static MockStreamerFactory.Op |
send(java.nio.ByteBuffer s)
Creates an operation of "SEND" type. |
static MockStreamerFactory.Op |
sendLoginFailed()
Helper: creates a "SEND" operation with the buffer telling that "login failed". |
static MockStreamerFactory.Op |
sendLoginOK()
Helper: creates a "SEND" operation with the buffer telling "login was OK". |
void |
setFormat(IFormat<java.nio.ByteBuffer> val)
Sets format. |
void |
setId(java.lang.String val)
Sets identification string. |
void |
setOpList(java.util.List<MockStreamerFactory.Op> val)
Sets op list. |
void |
setTrace(boolean val)
Sets trace flag. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public MockStreamerFactory()
Method Detail |
---|
public static java.nio.ByteBuffer parse(java.lang.String bufferString)
ByteBuffer
from
its hex-dump String representation.
bufferString
- string in the hex format.
public static java.nio.ByteBuffer parseResource(java.lang.String resourceName) throws java.io.IOException
ByteBuffer
by parsing
a resource file.
resourceName
- name of the resource.
java.io.IOException
- on IO error.public static MockStreamerFactory.Op sendLoginOK()
public static MockStreamerFactory.Op sendLoginFailed()
public IFormat<java.nio.ByteBuffer> getFormat()
BufferFormat
.
public void setFormat(IFormat<java.nio.ByteBuffer> val)
val
- format.public static MockStreamerFactory.Op expectAny()
public static MockStreamerFactory.Op expectBuffer(java.nio.ByteBuffer e)
e
- - model buffer.
public static MockStreamerFactory.Op send(java.nio.ByteBuffer s)
s
- buffer to send.
public java.util.List<MockStreamerFactory.Op> getOpList()
expectBuffer(ByteBuffer)
helper.
expectAny()
helper.
send(ByteBuffer)
helper.
public void setOpList(java.util.List<MockStreamerFactory.Op> val)
val
- op list.public boolean getTrace()
public void setTrace(boolean val)
val
- trace value.public java.lang.String getId()
public void setId(java.lang.String val)
val
- id string.public IStreamer connect(java.lang.String host, int port) throws java.io.IOException
IStreamerFactory
connect
in interface IStreamerFactory
java.io.IOException
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |