wavelet = new RobotWaveletData(obsWavelet, snapshot.committedVersion); return wavelet.getOpBasedWavelet(participant);
/** * Submits all deltas to the wavelet provider that are generated by the open * wavelets in the {@link OperationResults}. * * @param results the results of performing robot operations. * @param waveletProvider wavelet provider used to send the deltas to. * @param requestListener callback for deltas that are submitted to the * wavelet provider. */ public static void submitDeltas(OperationResults results, WaveletProvider waveletProvider, SubmitRequestListener requestListener) { for (Entry<WaveletName, RobotWaveletData> entry : results.getOpenWavelets().entrySet()) { WaveletName waveletName = entry.getKey(); RobotWaveletData w = entry.getValue(); for (WaveletDelta delta : w.getDeltas()) { ProtocolWaveletDelta protocolDelta = CoreWaveletOperationSerializer.serialize(delta); waveletProvider.submitRequest(waveletName, protocolDelta, requestListener); } } }
/** * Constructs a bound operation context. The bound wavelet is added to the * list of open wavelets. * * @param waveletProvider the waveletprovider to use for querying wavelet. * @param converter {@link EventDataConverter} for converting from server side * objects. * @param boundWavelet the wavelet to bind this context to, null for an * unbound context. * @param conversationUtil used to create conversations. */ public OperationContextImpl(WaveletProvider waveletProvider, EventDataConverter converter, ConversationUtil conversationUtil, RobotWaveletData boundWavelet) { this.waveletProvider = waveletProvider; this.converter = converter; this.conversationUtil = conversationUtil; this.boundWavelet = boundWavelet; this.openedConversations = Maps.newHashMap(); if (boundWavelet != null) { openedWavelets.put(boundWavelet.getWaveletName(), boundWavelet); } }
public void testDeltasAreReturnedInOrder() { // Alex adds a participant to the wavelet OpBasedWavelet waveletAlex = wavelet.getOpBasedWavelet(ALEX); waveletAlex.addParticipant(TRIXIE); // Bob adds a new document to the wavelet OpBasedWavelet waveletBob = wavelet.getOpBasedWavelet(BOB); waveletBob.getDocument("r+randomDocument").insertText(0, "/nHello"); List<WaveletDelta> deltas = wavelet.getDeltas(); assertTrue(deltas.size() == 2); assertEquals("Expected Alex to be first", ALEX, deltas.get(0).getAuthor()); assertEquals("Expected Bob to be the second author", BOB, deltas.get(1).getAuthor()); } }
public void testGetOpBasedWaveletReturnsSame() { OpBasedWavelet waveletAlex = wavelet.getOpBasedWavelet(ALEX); assertSame(waveletAlex, wavelet.getOpBasedWavelet(ALEX)); }
/** * Creates a new empty robot wavelet data. * * @param participant the wavelet creator. * @param waveletName the wavelet name. */ public static RobotWaveletData createEmptyRobotWavelet(ParticipantId participant, WaveletName waveletName) { HashedVersion hashedVersionZero = HASH_FACTORY.createVersionZero(waveletName); ObservableWaveletData emptyWavelet = WaveletDataUtil.createEmptyWavelet(waveletName, participant, hashedVersionZero, System.currentTimeMillis()); RobotWaveletData newWavelet = new RobotWaveletData(emptyWavelet, hashedVersionZero); return newWavelet; }
public void testDeltasAreReturnedInOrder() { // Alex adds a participant to the wavelet OpBasedWavelet waveletAlex = wavelet.getOpBasedWavelet(ALEX); waveletAlex.addParticipant(TRIXIE); // Bob adds a new document to the wavelet OpBasedWavelet waveletBob = wavelet.getOpBasedWavelet(BOB); waveletBob.getDocument("r+randomDocument").insertText(0, "/nHello"); List<WaveletDelta> deltas = wavelet.getDeltas(); assertTrue(deltas.size() == 2); assertEquals("Expected Alex to be first", ALEX, deltas.get(0).getAuthor()); assertEquals("Expected Bob to be the second author", BOB, deltas.get(1).getAuthor()); } }
public void testGetOpBasedWaveletReturnsSame() { OpBasedWavelet waveletAlex = wavelet.getOpBasedWavelet(ALEX); assertSame(waveletAlex, wavelet.getOpBasedWavelet(ALEX)); }
/** * Applies the operations within the context of the wavelet. * * @param operations the operations to apply * @param wavelet the wavelet which is the context in which this operation is * performed. * @param hashedVersion the version of the wavelet to which to apply the * operations to. * @param account the account for which to apply robot operations. */ void applyOperations(List<OperationRequest> operations, ReadableWaveletData wavelet, HashedVersion hashedVersion, RobotAccountData account) { // The robots we support should be sending us their version in their first // operation ProtocolVersion protocolVersion = OperationUtil.getProtocolVersion(operations); OperationContextImpl context = new OperationContextImpl(waveletProvider, converterManager.getEventDataConverter(protocolVersion), conversationUtil, new RobotWaveletData(wavelet, hashedVersion)); executeOperations(context, operations, account); handleResults(context, account); }
public void testGetDeltas() { // Alex adds a participant to the wavelet OpBasedWavelet waveletAlex = wavelet.getOpBasedWavelet(ALEX); waveletAlex.addParticipant(TRIXIE); // Bob doesn't perform any operations but we do retrieve his wavelet wavelet.getOpBasedWavelet(BOB); List<WaveletDelta> deltas = wavelet.getDeltas(); assertTrue("Only one participant has performed operations", deltas.size() == 1); WaveletDelta delta = deltas.get(0); HashedVersion version = delta.getTargetVersion(); assertEquals( "Delta should apply to the version given on construction", hashedVersionZero, version); assertEquals(ALEX, delta.getAuthor()); assertTrue(delta.size() == 1); AddParticipant addParticipantOp = new AddParticipant(null, TRIXIE); assertEquals("Expected operation that adds Trixie to the wavelet", addParticipantOp, delta.iterator().next()); }
public void testSubmitDeltas() { HashedVersion hashedVersionZero = HASH_FACTORY.createVersionZero(WAVELET_NAME); ObservableWaveletData waveletData = WaveletDataUtil.createEmptyWavelet(WAVELET_NAME, ALEX, hashedVersionZero, 0L); DocInitialization content = new DocInitializationBuilder().build(); waveletData.createDocument("b+example", BOB, Collections.singletonList(BOB), content, 0L, 0); RobotWaveletData wavelet = new RobotWaveletData(waveletData, hashedVersionZero); // Perform an operation that will be put into a delta wavelet.getOpBasedWavelet(BOB).addParticipant(ALEX); OperationResults results = mock(OperationResults.class); when(results.getOpenWavelets()).thenReturn(Collections.singletonMap(WAVELET_NAME, wavelet)); SubmitRequestListener requestListener = mock(SubmitRequestListener.class); OperationUtil.submitDeltas(results, waveletProvider, requestListener); verify(waveletProvider).submitRequest( eq(WAVELET_NAME), any(ProtocolWaveletDelta.class), eq(requestListener)); }
/** * Tests opening a wavelet that has to be retrieved using the * {@link WaveletProvider}. */ public void testOpenWaveletFromWaveletProvider() throws Exception { OpBasedWavelet opBasedWavelet = wavelet.getOpBasedWavelet(PARTICIPANT); assertEquals(opBasedWavelet, operationContext.openWavelet(WAVE_ID, WAVELET_ID, PARTICIPANT)); }
@Override protected void setUp() throws Exception { converter = mock(EventDataConverter.class); waveletProvider = mock(WaveletProvider.class); conversationUtil = mock(ConversationUtil.class); request = new OperationRequest("wave.setTitle", OPERATION_ID); operationContext = new OperationContextImpl(waveletProvider, converter, conversationUtil); waveletData = WaveletDataUtil.createEmptyWavelet(WAVELET_NAME, PARTICIPANT, HASH_FACTORY.createVersionZero(WAVELET_NAME), 0L); waveletData.addParticipant(PARTICIPANT); HashedVersion hashedVersionZero = HASH_FACTORY.createVersionZero(WAVELET_NAME); wavelet = new RobotWaveletData(waveletData, hashedVersionZero); when(waveletProvider.checkAccessPermission(WAVELET_NAME, PARTICIPANT)).thenReturn(true); CommittedWaveletSnapshot snapshotAndVersion = new CommittedWaveletSnapshot( waveletData, hashedVersionZero); when(waveletProvider.getSnapshot(WAVELET_NAME)).thenReturn(snapshotAndVersion); boundOperationContext = new OperationContextImpl(waveletProvider, converter, conversationUtil, wavelet); }
@Override public void putWavelet(WaveId waveId, WaveletId waveletId, RobotWaveletData newWavelet) { WaveletName waveletName = newWavelet.getWaveletName(); Preconditions.checkArgument(!openedWavelets.containsKey(waveletName), "Not allowed to put an already open wavelet in as a new wavelet"); // New wavelets are indicated by the temporary marker in their waveId. if (waveId.getId().startsWith(TEMP_ID_MARKER)) { tempWaveletNameMap.put(WaveletName.of(waveId, waveletId), waveletName); } openedWavelets.put(waveletName, newWavelet); }
assertNotNull("A new wavelet must be open", newWavelet); List<WaveletDelta> deltas = newWavelet.getDeltas(); boolean seenAddAlex = false; boolean seenAddBob = false;
public void testGetDeltas() { // Alex adds a participant to the wavelet OpBasedWavelet waveletAlex = wavelet.getOpBasedWavelet(ALEX); waveletAlex.addParticipant(TRIXIE); // Bob doesn't perform any operations but we do retrieve his wavelet wavelet.getOpBasedWavelet(BOB); List<WaveletDelta> deltas = wavelet.getDeltas(); assertTrue("Only one participant has performed operations", deltas.size() == 1); WaveletDelta delta = deltas.get(0); HashedVersion version = delta.getTargetVersion(); assertEquals( "Delta should apply to the version given on construction", hashedVersionZero, version); assertEquals(ALEX, delta.getAuthor()); assertTrue(delta.size() == 1); AddParticipant addParticipantOp = new AddParticipant(null, TRIXIE); assertEquals("Expected operation that adds Trixie to the wavelet", addParticipantOp, delta.iterator().next()); }
public void testSubmitDeltas() { HashedVersion hashedVersionZero = HASH_FACTORY.createVersionZero(WAVELET_NAME); ObservableWaveletData waveletData = WaveletDataUtil.createEmptyWavelet(WAVELET_NAME, ALEX, hashedVersionZero, 0L); DocInitialization content = new DocInitializationBuilder().build(); waveletData.createDocument("b+example", BOB, Collections.singletonList(BOB), content, 0L, 0); RobotWaveletData wavelet = new RobotWaveletData(waveletData, hashedVersionZero); // Perform an operation that will be put into a delta wavelet.getOpBasedWavelet(BOB).addParticipant(ALEX); OperationResults results = mock(OperationResults.class); when(results.getOpenWavelets()).thenReturn(Collections.singletonMap(WAVELET_NAME, wavelet)); SubmitRequestListener requestListener = mock(SubmitRequestListener.class); OperationUtil.submitDeltas(results, waveletProvider, requestListener); verify(waveletProvider).submitRequest( eq(WAVELET_NAME), any(ProtocolWaveletDelta.class), eq(requestListener)); }
/** * Tests opening a wavelet that has to be retrieved using the * {@link WaveletProvider}. */ public void testOpenWaveletFromWaveletProvider() throws Exception { OpBasedWavelet opBasedWavelet = wavelet.getOpBasedWavelet(PARTICIPANT); assertEquals(opBasedWavelet, operationContext.openWavelet(WAVE_ID, WAVELET_ID, PARTICIPANT)); }
@Override protected void setUp() throws Exception { converter = mock(EventDataConverter.class); waveletProvider = mock(WaveletProvider.class); conversationUtil = mock(ConversationUtil.class); request = new OperationRequest("wave.setTitle", OPERATION_ID); operationContext = new OperationContextImpl(waveletProvider, converter, conversationUtil); waveletData = WaveletDataUtil.createEmptyWavelet(WAVELET_NAME, PARTICIPANT, HASH_FACTORY.createVersionZero(WAVELET_NAME), 0L); waveletData.addParticipant(PARTICIPANT); HashedVersion hashedVersionZero = HASH_FACTORY.createVersionZero(WAVELET_NAME); wavelet = new RobotWaveletData(waveletData, hashedVersionZero); when(waveletProvider.checkAccessPermission(WAVELET_NAME, PARTICIPANT)).thenReturn(true); CommittedWaveletSnapshot snapshotAndVersion = new CommittedWaveletSnapshot( waveletData, hashedVersionZero); when(waveletProvider.getSnapshot(WAVELET_NAME)).thenReturn(snapshotAndVersion); boundOperationContext = new OperationContextImpl(waveletProvider, converter, conversationUtil, wavelet); }
public void testGetWaveletName() { assertEquals(wavelet.getWaveletName(), WAVELET_NAME); }