Socket socket = new Socket();
socket.setReceiveBufferSize(1000000);
socket.setTcpNoDelay(true);
socket.connect(ServerAddr, 500);
ReplSessionSecurity replSessionSecurity = getReplSessionSecurity();
ProtocolSession session =
replSessionSecurity.createClientSession(serverURL, socket,
ReplSessionSecurity.HANDSHAKE_TIMEOUT);
boolean sslEncryption =
DirectoryConfig.getCryptoManager().isSslEncryption();
try
{
// send a ServerStartMsg with an empty ServerState.
ServerStartMsg msg =
new ServerStartMsg( 1723, TEST_ROOT_DN_STRING,
WINDOW, (long) 5000, new ServerState(),
ProtocolVersion.getCurrentVersion(), 0, sslEncryption, (byte)-1);
session.publish(msg);
// Read the Replication Server state from the ReplServerStartDSMsg that
// comes back.
ReplServerStartDSMsg replStartDSMsg =
(ReplServerStartDSMsg) session.receive();
int serverwindow = replStartDSMsg.getWindowSize();
ServerState replServerState = replStartDSMsg.getServerState();
if (!sslEncryption)
{
session.stopEncryption();
}
// Send StartSessionMsg
StartSessionMsg startSessionMsg =
new StartSessionMsg(ServerStatus.NORMAL_STATUS,
new ArrayList<String>());
session.publish(startSessionMsg);
// Read the TopologyMsg that should come back.
ReplicationMsg repMsg = session.receive();
assertTrue(repMsg instanceof TopologyMsg);
// close the session
session.close();
// Sleep a while so the following connection is not perturbed by some
// topo messages signalling first connection has been dropped: let
// disocnnection fully happen before, connecting a second session
Thread.sleep(2000);
// open a new session to the replication Server
socket = new Socket();
socket.setReceiveBufferSize(1000000);
socket.setTcpNoDelay(true);
socket.connect(ServerAddr, 500);
session = replSessionSecurity.createClientSession(serverURL, socket, 4000);
// send a ServerStartMsg containing the ServerState that was just
// received.
DN baseDn = DN.decode(TEST_ROOT_DN_STRING);
msg = new ServerStartMsg(
1724, TEST_ROOT_DN_STRING,
WINDOW, (long) 5000, replServerState,
ProtocolVersion.getCurrentVersion(),
ReplicationTestCase.getGenerationId(baseDn),
sslEncryption, (byte)10);
session.publish(msg);
// Read the ReplServerStartDSMsg that should come back.
repMsg = session.receive();
assertTrue(repMsg instanceof ReplServerStartDSMsg);
if (!sslEncryption)
{
session.stopEncryption();
}
// Send StartSessionMsg
startSessionMsg = new StartSessionMsg(ServerStatus.NORMAL_STATUS,
new ArrayList<String>());
session.publish(startSessionMsg);
// Read the TopologyMsg that should come back.
repMsg = session.receive();
assertTrue(repMsg instanceof TopologyMsg);
// Now comes the real test : check that the Replication Server
// answers correctly to a WindowProbeMsg Message.
session.publish(new WindowProbeMsg());
WindowMsg windowMsg = (WindowMsg) session.receive();
assertEquals(serverwindow, windowMsg.getNumAck());
// check that this did not change the window by sending a probe again.
session.publish(new WindowProbeMsg());
// We may receive some MonitoringMsg so use filter method
windowMsg = (WindowMsg)waitForSpecificMsg(session, WindowMsg.class.getName());
assertEquals(serverwindow, windowMsg.getNumAck());
debugInfo("Ending windowProbeTest");
}
finally
{
session.close();
}
}