Package org.axonframework.saga

Examples of org.axonframework.saga.AssociationValue


    private Set<AssociationValue> toAssociationSet(DBObject dbSaga) {
        Set<AssociationValue> values = new HashSet<AssociationValue>();
        List<DBObject> list = (List<DBObject>) dbSaga.get(ASSOCIATIONS);
        if (list != null) {
            for (DBObject item : list) {
                values.add(new AssociationValue((String) item.get(ASSOCIATION_KEY),
                                                (String) item.get(ASSOCIATION_VALUE)));
            }
        }
        return values;
    }
View Full Code Here


                    }
                });
        // the event is scheduled in 50ms, which is generally enough to get the saga committed
        Thread.sleep(150);
        Set<String> actualResult = repository.find(SimpleTimingSaga.class,
                                                   new AssociationValue("association", someAssociationValue));
        assertEquals(1, actualResult.size());
        SimpleTimingSaga saga = (SimpleTimingSaga) repository.load(actualResult.iterator().next());
        assertTrue("Expected saga to be triggered", saga.isTriggered());
        // we make sure all submitted jobs are executed successfully. get() will throw an exception if a job had failed
        for (Future<?> future : executorService.getResults()) {
View Full Code Here

     *
     * @param identifier the identifier to initialize the saga with.
     */
    protected AbstractAnnotatedSaga(String identifier) {
        this.identifier = identifier;
        associationValues.add(new AssociationValue("sagaIdentifier", identifier));
    }
View Full Code Here

     *
     * @param key   The key of the association value to associate this saga with.
     * @param value The value of the association value to associate this saga with.
     */
    protected void associateWith(String key, String value) {
        associationValues.add(new AssociationValue(key, value));
    }
View Full Code Here

     *
     * @param key   The key of the association value to remove from this saga.
     * @param value The value of the association value to remove from this saga.
     */
    protected void removeAssociationWith(String key, String value) {
        associationValues.remove(new AssociationValue(key, value));
    }
View Full Code Here

     * @param event  The event to find a handler for
     * @return the most suitable handler for the event on the target, or an instance describing no such handler exists
     */
    public SagaMethodMessageHandler findHandlerMethod(AbstractAnnotatedSaga target, EventMessage event) {
        for (SagaMethodMessageHandler handler : getMessageHandlers(event)) {
            final AssociationValue associationValue = handler.getAssociationValue(event);
            if (target.getAssociationValues().contains(associationValue)) {
                return handler;
            } else if (logger.isDebugEnabled()) {
                logger.debug(
                        "Skipping handler [{}], it requires an association value [{}:{}] that this Saga is not associated with",
                        handler.getName(),
                        associationValue.getKey(),
                        associationValue.getValue());
            }
        }
        if (logger.isDebugEnabled()) {
            logger.debug("No suitable handler was found for event of type", event.getPayloadType().getName());
        }
View Full Code Here

    @DirtiesContext
    @Test
    public void testLoadSagaOfDifferentTypesWithSameAssociationValue_SagaFound() {
        MyTestSaga testSaga = new MyTestSaga("test1");
        MyOtherTestSaga otherTestSaga = new MyOtherTestSaga("test2");
        testSaga.registerAssociationValue(new AssociationValue("key", "value"));
        otherTestSaga.registerAssociationValue(new AssociationValue("key", "value"));
        repository.add(testSaga);
        repository.add(otherTestSaga);
        Set<String> actual = repository.find(MyTestSaga.class, new AssociationValue("key", "value"));
        assertEquals(1, actual.size());
        assertEquals(MyTestSaga.class, repository.load(actual.iterator().next()).getClass());

        Set<String> actual2 = repository.find(MyOtherTestSaga.class, new AssociationValue("key", "value"));
        assertEquals(1, actual2.size());
        assertEquals(MyOtherTestSaga.class, repository.load(actual2.iterator().next()).getClass());

        DBObject sagaQuery = SagaEntry.queryByIdentifier("test1");
        DBCursor sagaCursor = mongoTemplate.sagaCollection().find(sagaQuery);
View Full Code Here

    @DirtiesContext
    @Test
    public void testLoadSagaOfDifferentTypesWithSameAssociationValue_NoSagaFound() {
        MyTestSaga testSaga = new MyTestSaga("test1");
        testSaga.registerAssociationValue(new AssociationValue("key", "value"));
        MyOtherTestSaga otherTestSaga = new MyOtherTestSaga("test2");
        otherTestSaga.registerAssociationValue(new AssociationValue("key", "value"));
        repository.add(testSaga);
        repository.add(otherTestSaga);
        Set<String> actual = repository.find(InexistentSaga.class, new AssociationValue("key", "value"));
        assertTrue("Didn't expect any sagas", actual.isEmpty());
    }
View Full Code Here

    @DirtiesContext
    public void testLoadSagaOfDifferentTypesWithSameAssociationValue_SagaDeleted() {
        MyTestSaga testSaga = new MyTestSaga("test1");
        MyOtherTestSaga otherTestSaga = new MyOtherTestSaga("test2");
        repository.add(testSaga);
        testSaga.registerAssociationValue(new AssociationValue("key", "value"));
        otherTestSaga.registerAssociationValue(new AssociationValue("key", "value"));
        testSaga.end(); // make the saga inactive
        repository.add(otherTestSaga);
        repository.commit(testSaga); //remove the saga because it is inactive
        Set<String> actual = repository.find(MyTestSaga.class, new AssociationValue("key", "value"));
        assertTrue("Didn't expect any sagas", actual.isEmpty());

        DBObject sagaQuery = SagaEntry.queryByIdentifier("test1");
        DBCursor sagaCursor = mongoTemplate.sagaCollection().find(sagaQuery);
        assertEquals("No saga is expected after .end and .commit", 0, sagaCursor.size());
View Full Code Here

    @DirtiesContext
    @Test
    public void testAddAndLoadSaga_ByAssociationValue() {
        String identifier = UUID.randomUUID().toString();
        MyTestSaga saga = new MyTestSaga(identifier);
        saga.registerAssociationValue(new AssociationValue("key", "value"));
        repository.add(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

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.