Package org.axonframework.saga

Examples of org.axonframework.saga.AssociationValue


    public void testAddAndLoadSaga_MultipleHitsByAssociationValue() {
        String identifier1 = UUID.randomUUID().toString();
        String identifier2 = UUID.randomUUID().toString();
        MyTestSaga saga1 = new MyTestSaga(identifier1);
        MyOtherTestSaga saga2 = new MyOtherTestSaga(identifier2);
        saga1.registerAssociationValue(new AssociationValue("key", "value"));
        saga2.registerAssociationValue(new AssociationValue("key", "value"));
        repository.add(saga1);
        repository.add(saga2);

        // load saga1
        Set<String> loaded1 = repository.find(MyTestSaga.class, new AssociationValue("key", "value"));
        assertEquals(1, loaded1.size());
        MyTestSaga loadedSaga1 = (MyTestSaga) repository.load(loaded1.iterator().next());
        assertEquals(identifier1, loadedSaga1.getSagaIdentifier());
        assertNotNull(mongoTemplate.sagaCollection().find(SagaEntry.queryByIdentifier(identifier1)));

        // load saga2
        Set<String> loaded2 = repository.find(MyOtherTestSaga.class, new AssociationValue("key", "value"));
        assertEquals(1, loaded2.size());
        MyOtherTestSaga loadedSaga2 = (MyOtherTestSaga) repository.load(loaded2.iterator().next());
        assertEquals(identifier2, loadedSaga2.getSagaIdentifier());
        assertNotNull(mongoTemplate.sagaCollection().find(SagaEntry.queryByIdentifier(identifier2)));
    }
View Full Code Here


    @DirtiesContext
    public void testAddAndLoadSaga_AssociateValueAfterStorage() {
        String identifier = UUID.randomUUID().toString();
        MyTestSaga saga = new MyTestSaga(identifier);
        repository.add(saga);
        saga.registerAssociationValue(new AssociationValue("key", "value"));
        repository.commit(saga);
        Set<String> loaded = repository.find(MyTestSaga.class, new AssociationValue("key", "value"));
        assertEquals(1, loaded.size());
        MyTestSaga loadedSaga = (MyTestSaga) repository.load(loaded.iterator().next());
        assertEquals(identifier, loadedSaga.getSagaIdentifier());
        assertNotNull(mongoTemplate.sagaCollection().find(SagaEntry.queryByIdentifier(identifier)));
    }
View Full Code Here

    @DirtiesContext
    @Test
    public void testLoadSaga_AssociationValueRemoved() {
        String identifier = UUID.randomUUID().toString();
        MyTestSaga saga = new MyTestSaga(identifier);
        saga.registerAssociationValue(new AssociationValue("key", "value"));
        mongoTemplate.sagaCollection().save(new SagaEntry(saga, new JavaSerializer()).asDBObject());

        MyTestSaga loaded = (MyTestSaga) repository.load(identifier);
        loaded.removeAssociationValue("key", "value");
        repository.commit(loaded);
        Set<String> found = repository.find(MyTestSaga.class, new AssociationValue("key", "value"));
        assertEquals(0, found.size());
    }
View Full Code Here

                    @Override
                    public void doInTransactionWithoutResult(TransactionStatus status) {
                        eventBus.publish(new GenericEventMessage<StartingEvent>(new StartingEvent(randomAssociationValue)));
                        Set<String> actualResult =
                                repository.find(SimpleTimingSaga.class,
                                                new AssociationValue("association", randomAssociationValue));
                        assertEquals(1, actualResult.size());
                    }
                });

        SimpleTimingSaga saga = null;
        long t1 = System.currentTimeMillis();
        while (saga == null || !saga.isTriggered()) {
            if (System.currentTimeMillis() - t1 > 1000) {
                fail("Saga not triggered within 1000 milliseconds");
            }
            Set<String> actualResult;
            actualResult = repository.find(SimpleTimingSaga.class,
                                           new AssociationValue("association", randomAssociationValue));
            assertEquals(1, actualResult.size());
            saga = (SimpleTimingSaga) repository.load(actualResult.iterator().next());
        }
        assertTrue("Expected saga to be triggered", saga.isTriggered());
        assertTrue("Job did not complete within 10 seconds", jobExecutionLatch.await(10, TimeUnit.SECONDS));
View Full Code Here

     * Returns the association value contained in this entry.
     *
     * @return the association value contained in this entry
     */
    public AssociationValue getAssociationValue() {
        return new AssociationValue(associationKey, associationValue);
    }
View Full Code Here

     * @param associationKey   The key of the association
     * @param associationValue The value of the association
     */
    public void assertAssociationPresent(String associationKey, String associationValue) {
        Set<String> associatedSagas =
                sagaRepository.find(sagaType, new AssociationValue(associationKey, associationValue));
        if (associatedSagas.isEmpty()) {
            throw new AxonAssertionError(format(
                    "Expected a saga to be associated with key:<%s> value:<%s>, but found <none>",
                    associationKey,
                    associationValue));
View Full Code Here

     * @param associationKey   The key of the association
     * @param associationValue The value of the association
     */
    public void assertNoAssociationPresent(String associationKey, String associationValue) {
        Set<String> associatedSagas =
                sagaRepository.find(sagaType, new AssociationValue(associationKey, associationValue));
        if (!associatedSagas.isEmpty()) {
            throw new AxonAssertionError(format(
                    "Expected a saga to be associated with key:<%s> value:<%s>, but found <%s>",
                    associationKey,
                    associationValue,
View Full Code Here

                    newAssociation.toString())));
            currentAssociation = newAssociation;
        }
        sagaManager.stop();
        Set<String> result = sagaRepository.find(AsyncSaga.class,
                                                 new AssociationValue("currentAssociation",
                                                                      currentAssociation.toString()));
        assertEquals(1, result.size());
    }
View Full Code Here

        assertEquals("Did not expect any live Sagas", 0, sagaEntryCount);
        assertEquals("Did not expect any association values", 0, associationValuesCount);
    }

    private void validateSaga(UUID myId) {
        Set<String> sagas = sagaRepository.find(AsyncSaga.class, new AssociationValue("myId", myId.toString()));
        assertEquals(1, sagas.size());
        AsyncSaga saga = (AsyncSaga) sagaRepository.load(sagas.iterator().next());
        Iterator<String> messageIterator = saga.getReceivedMessages().iterator();
        for (int t = 0; t < EVENTS_PER_SAGA; t++) {
            assertEquals("Message out of order in saga " + saga.getSagaIdentifier(),
View Full Code Here

TOP

Related Classes of org.axonframework.saga.AssociationValue

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.