@Test public void testPendingMessagesAreDeliveredAtStartup() throws Exception { Transaction txn = new Transaction(null, true); Transaction txn1 = new Transaction(null, true); Transaction txn2 = new Transaction(null, false); Transaction txn3 = new Transaction(null, false); Transaction txn4 = new Transaction(null, true); context.checking(new Expectations() {{ oneOf(db).startTransaction(true); will(returnValue(txn)); oneOf(db).getMessagesToValidate(txn); will(returnValue(Collections.emptyList())); oneOf(db).commitTransaction(txn); oneOf(db).endTransaction(txn); oneOf(db).startTransaction(true); will(returnValue(txn1)); oneOf(db).getPendingMessages(txn1); will(returnValue(Collections.singletonList(messageId))); oneOf(db).commitTransaction(txn1); oneOf(db).endTransaction(txn1); oneOf(db).startTransaction(false); will(returnValue(txn2)); oneOf(db).getMessageState(txn2, messageId); will(returnValue(PENDING)); oneOf(db).getMessageDependencies(txn2, messageId); will(returnValue(Collections.singletonMap(messageId1, DELIVERED))); oneOf(db).getRawMessage(txn2, messageId); will(returnValue(raw)); oneOf(messageFactory).createMessage(messageId, raw); will(returnValue(message)); oneOf(db).getGroup(txn2, groupId); will(returnValue(group)); oneOf(db).getMessageMetadataForValidator(txn2, messageId); will(returnValue(new Metadata())); oneOf(hook).incomingMessage(txn2, message, metadata); will(returnValue(false)); oneOf(db).setMessageState(txn2, messageId, DELIVERED); oneOf(db).getMessageDependents(txn2, messageId); will(returnValue(Collections.singletonMap(messageId2, PENDING))); oneOf(db).commitTransaction(txn2); oneOf(db).endTransaction(txn2); oneOf(db).startTransaction(false); will(returnValue(txn3)); oneOf(db).getMessageState(txn3, messageId2); will(returnValue(PENDING)); oneOf(db).getMessageDependencies(txn3, messageId2); will(returnValue(Collections.singletonMap(messageId1, DELIVERED))); oneOf(db).getRawMessage(txn3, messageId2); will(returnValue(raw)); oneOf(messageFactory).createMessage(messageId2, raw); will(returnValue(message2)); oneOf(db).getGroup(txn3, groupId); will(returnValue(group)); oneOf(db).getMessageMetadataForValidator(txn3, messageId2); will(returnValue(metadata)); oneOf(hook).incomingMessage(txn3, message2, metadata); will(returnValue(false)); oneOf(db).setMessageState(txn3, messageId2, DELIVERED); oneOf(db).getMessageDependents(txn3, messageId2); will(returnValue(Collections.emptyMap())); oneOf(db).commitTransaction(txn3); oneOf(db).endTransaction(txn3); oneOf(db).startTransaction(true); will(returnValue(txn4)); oneOf(db).getMessagesToShare(txn4); will(returnValue(Collections.emptyList())); oneOf(db).commitTransaction(txn4); oneOf(db).endTransaction(txn4); }}); vm.startService(); }
@Override public void startService() { if (used.getAndSet(true)) throw new IllegalStateException(); validateOutstandingMessagesAsync(); deliverOutstandingMessagesAsync(); shareOutstandingMessagesAsync(); }
ValidationManagerImpl implements ValidationManager, Service,
		EventListener { @Override public void startService() { if (used.getAndSet(true)) throw new IllegalStateException(); validateOutstandingMessagesAsync(); deliverOutstandingMessagesAsync(); shareOutstandingMessagesAsync(); } }
ValidationManagerImpl implements ValidationManager, Service,
		EventListener { @Override public void startService() { if (used.getAndSet(true)) throw new IllegalStateException(); validateOutstandingMessagesAsync(); deliverOutstandingMessagesAsync(); shareOutstandingMessagesAsync(); } @Inject  ValidationManagerImpl(DatabaseComponent db,
			@DatabaseExecutor Executor dbExecutor,
			@ValidationExecutor Executor validationExecutor,
			MessageFactory messageFactory); }
ValidationManagerImpl implements ValidationManager, Service,
		EventListener { @Override public void startService() { if (used.getAndSet(true)) throw new IllegalStateException(); validateOutstandingMessagesAsync(); deliverOutstandingMessagesAsync(); shareOutstandingMessagesAsync(); } @Inject  ValidationManagerImpl(DatabaseComponent db,
			@DatabaseExecutor Executor dbExecutor,
			@ValidationExecutor Executor validationExecutor,
			MessageFactory messageFactory); @Override void startService(); @Override void stopService(); @Override void registerMessageValidator(ClientId c, int majorVersion,
			MessageValidator v); @Override void registerIncomingMessageHook(ClientId c, int majorVersion,
			IncomingMessageHook hook); @Override void eventOccurred(Event e); }
ValidationManagerImpl implements ValidationManager, Service,
		EventListener { @Override public void startService() { if (used.getAndSet(true)) throw new IllegalStateException(); validateOutstandingMessagesAsync(); deliverOutstandingMessagesAsync(); shareOutstandingMessagesAsync(); } @Inject  ValidationManagerImpl(DatabaseComponent db,
			@DatabaseExecutor Executor dbExecutor,
			@ValidationExecutor Executor validationExecutor,
			MessageFactory messageFactory); @Override void startService(); @Override void stopService(); @Override void registerMessageValidator(ClientId c, int majorVersion,
			MessageValidator v); @Override void registerIncomingMessageHook(ClientId c, int majorVersion,
			IncomingMessageHook hook); @Override void eventOccurred(Event e);  }