/** * Pretend client did some ops. * * Assumption: Noops are not merged in OperationMergingDelta. If they are, then tests * will break as they count the number of ops sent from the client to the server. * * @throws TransformException */ public TestConfig clientDoOps(int numOps) throws OperationException, TransformException { for (int i = 0; i < numOps; i++) { clientMock.addClientOperation(new NoOp(new WaveletOperationContext( clientMock.getParticipantId(), 0L, 1L))); } clientMock.flush(); return this; }
/** * Pretend a client did the given op, so that when we call flush, the operation will * be ejected. */ public void addClientOperation(WaveletOperation operation) throws OperationException { clientOperations.add(operation); if (doc != null) { applyOperation(operation); } }
private void clientReceiveOpFromCC(boolean expectOps) { if (expectOps) { assertTrue(clientMock.getNumOpsReceived() > 0); } clientMock.clearEvents(); clientMock.receiveServerOperations(); }
/** * Pretend client did some ops at the given op versions. * @throws OperationException * @throws TransformException */ private TestConfig clientDoOps(WaveletOperation ... ops) throws OperationException, TransformException { for (WaveletOperation op : ops) { clientMock.addClientOperation(op); } clientMock.flush(); return this; }
/** * Pretend client did some insert at the given op versions. We don't need a version * number as it's inferred in client CC. * * @throws OperationException * @throws TransformException */ public TestConfig clientDoInsert(int insertionPoint, String content, boolean flush) throws OperationException, TransformException { clientMock.doInsert(insertionPoint, content); if (flush) { clientMock.flush(); } return this; }
/** * Turn all the deltas sent by a client into ghosts. * @param ghostSend should the client's out going ops be ghosted. */ public void ghostClientDeltas(int clientNumber, boolean ghostSend) { ClientMock client = clientMocks.get(clientNumber); ServerConnectionMock connection = client.getConnection(); connection.setGhostSend(ghostSend); }
/** * Reconnect a single client from server * @throws OperationException * @throws TransformException */ public void reconnectClient(int clientNumber) throws ChannelException, TransformException, OperationException { ClientMock client = clientMocks.get(clientNumber); ServerConnectionMock connection = client.getConnection(); serverMock.addClientConnection(connection); connection.setServerMock(serverMock); connection.setOpen(true); connection.reconnect(client.getReconnectionVersions()); }
/** * Pretend the server echos back client's operation. */ public TestConfig serverDoEchoBack(int startVersion, long timestamp) throws TransformException, OperationException { TransformedWaveletDelta d = TransformedWaveletDelta.cloneOperations( clientMock.getParticipantId(), genSignature(startVersion + 1), timestamp, Arrays.asList(SERVER_UTIL.noOp())); serverConnectionMock.triggerServerDeltas(Collections.singletonList(d)); return this; }
/** * Check client has a document that looks like the following. */ public TestConfig checkClientDoc(String xml) { DocInitialization expected = parse(xml).asOperation(); DocInitialization actual = clientMock.getDoc().asOperation(); assertTrue(OpComparators.SYNTACTIC_IDENTITY.equal(expected, actual)); return this; } }
public void init(int version, String intialBlipXml) { HashedVersion signature = genSignature(version); serverConnectionMock = new ServerConnectionMock(); ConcurrencyControl clientCC = new ConcurrencyControl(logger, signature); serverConnectionMock.setListener(clientCC); clientMock = new ClientMock( clientCC, intialBlipXml != null ? parse(intialBlipXml) : null, DEFAULT_CREATOR, serverConnectionMock); clientCC.initialise(serverConnectionMock, clientMock); try { clientCC.onOpen(signature, signature); } catch (ChannelException e) { fail("onOpen failed: " + e); } }
t.checkClientDoc("<blip><p>XYabc</p></blip>"); t.serverDoInsert(0, 3, "A", 4).serverDoInsert(1, 4, "B", 4); t.clientMock.flush(); t.checkClientGotOps(0, 2).checkClientSentOps().checkClientDoc("<blip><p>XYaABbc</p></blip>");
/** * Pretend client did some ops at the given op versions. * @throws OperationException * @throws TransformException */ private TestConfig clientDoOps(WaveletOperation ... ops) throws OperationException, TransformException { for (WaveletOperation op : ops) { clientMock.addClientOperation(op); } clientMock.flush(); return this; }
/** * Pretend client did some insert at the given op versions. We don't need a version * number as it's inferred in client CC. * * @throws OperationException * @throws TransformException */ public TestConfig clientDoInsert(int insertionPoint, String content, boolean flush) throws OperationException, TransformException { clientMock.doInsert(insertionPoint, content); if (flush) { clientMock.flush(); } return this; }
/** * Send all the ghosted deltas from a client. */ public void sendGhostDeltas(int clientNumber) { ClientMock client = clientMocks.get(clientNumber); ServerConnectionMock connection = client.getConnection(); connection.sendGhosts(); }
/** * Reconnect a single client from server * @throws OperationException * @throws TransformException */ public void reconnectClient(int clientNumber) throws ChannelException, TransformException, OperationException { ClientMock client = clientMocks.get(clientNumber); ServerConnectionMock connection = client.getConnection(); serverMock.addClientConnection(connection); connection.setServerMock(serverMock); connection.setOpen(true); connection.reconnect(client.getReconnectionVersions()); }
/** * Pretend the server echos back client's operation. Timestamp default to 0L. */ public TestConfig serverDoEchoBackDocOp(int startVersion, String blipId) throws TransformException, OperationException { TransformedWaveletDelta d = TransformedWaveletDelta.cloneOperations( clientMock.getParticipantId(), genSignature(startVersion + 1), 0L, Arrays.asList(noOpDocOp(blipId))); serverConnectionMock.triggerServerDeltas(Collections.singletonList(d)); return this; }
/** * Check client has a document that looks like the following. */ public TestConfig checkClientDoc(int clientNumber, String xml) { clientsReceiveServerOperations(); DocInitialization expected = parse(xml).asOperation(); DocInitialization actual = clientMocks.get(clientNumber).getDoc().asOperation(); assertTrue("[Expected: " + expected + "] [Actual: " + actual + "]", OpComparators.SYNTACTIC_IDENTITY.equal(expected, actual)); return this; }
public void init(int version, String intialBlipXml) { HashedVersion signature = genSignature(version); serverConnectionMock = new ServerConnectionMock(); ConcurrencyControl clientCC = new ConcurrencyControl(logger, signature); serverConnectionMock.setListener(clientCC); clientMock = new ClientMock( clientCC, intialBlipXml != null ? parse(intialBlipXml) : null, DEFAULT_CREATOR, serverConnectionMock); clientCC.initialise(serverConnectionMock, clientMock); try { clientCC.onOpen(signature, signature); } catch (ChannelException e) { fail("onOpen failed: " + e); } }
t.checkClientDoc("<blip><p>XYabc</p></blip>"); t.serverDoInsert(0, 3, "A", 4).serverDoInsert(1, 4, "B", 4); t.clientMock.flush(); t.checkClientGotOps(0, 2).checkClientSentOps().checkClientDoc("<blip><p>XYaABbc</p></blip>");
private void clientReceiveOpFromCC(boolean expectOps) { if (expectOps) { assertTrue(clientMock.getNumOpsReceived() > 0); } clientMock.clearEvents(); clientMock.receiveServerOperations(); }