Search in sources :

Example 11 with Fail

use of org.wso2.carbon.humantask.core.engine.commands.Fail in project siddhi by wso2.

the class InMemoryTransportTestCase method inMemoryTestCase8.

@Test(expectedExceptions = SiddhiAppCreationException.class)
public void inMemoryTestCase8() throws InterruptedException {
    log.info("Test inMemory 8");
    String streams = "" + "@app:name('TestSiddhiApp')" + "@source(type='testEventInMemory', topic='Foo', prop1='hi', prop2='test', fail='true', " + "   @map(type='testString', @attributes(symbol='trp:symbol'," + "        volume='volume',price='trp:price'))) " + "define stream FooStream (symbol string, price string, volume long); " + "define stream BarStream (symbol string, price string, volume long); ";
    String query = "" + "from FooStream " + "select * " + "insert into BarStream; ";
    SiddhiManager siddhiManager = new SiddhiManager();
    SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(streams + query);
}
Also used : SiddhiAppRuntime(org.wso2.siddhi.core.SiddhiAppRuntime) SiddhiManager(org.wso2.siddhi.core.SiddhiManager) Test(org.testng.annotations.Test)

Example 12 with Fail

use of org.wso2.carbon.humantask.core.engine.commands.Fail in project siddhi by wso2.

the class IndexOperator method update.

private void update(IndexedEventHolder storeEvents, InMemoryCompiledUpdateSet compiledUpdateSet, StateEvent overwritingOrAddingEvent, ComplexEventChunk<StreamEvent> foundEventChunk) {
    // for cases when indexed attribute is also updated but that not changed
    // to reduce number of passes needed to update the events
    boolean doDeleteUpdate = false;
    boolean fail = false;
    for (Map.Entry<Integer, ExpressionExecutor> entry : compiledUpdateSet.getExpressionExecutorMap().entrySet()) {
        if (doDeleteUpdate || fail) {
            break;
        }
        if (storeEvents.isAttributeIndexed(entry.getKey())) {
            // Todo how much check we need to do before falling back to Delete and then Update
            foundEventChunk.reset();
            Set<Object> keys = null;
            PrimaryKeyReferenceHolder[] primaryKeyReferenceHolders = storeEvents.getPrimaryKeyReferenceHolders();
            if (primaryKeyReferenceHolders != null && primaryKeyReferenceHolders.length == 1 && entry.getKey() == primaryKeyReferenceHolders[0].getPrimaryKeyPosition()) {
                keys = new HashSet<>(storeEvents.getAllPrimaryKeyValues());
            }
            while (foundEventChunk.hasNext()) {
                StreamEvent streamEvent = foundEventChunk.next();
                Object updatingData = entry.getValue().execute(overwritingOrAddingEvent);
                Object storeEventData = streamEvent.getOutputData()[entry.getKey()];
                if (updatingData != null && storeEventData != null && !updatingData.equals(storeEventData)) {
                    doDeleteUpdate = true;
                    if (keys == null || keys.size() == 0) {
                        break;
                    } else {
                        keys.remove(storeEventData);
                        if (!keys.add(updatingData)) {
                            log.error("Update failed for event :" + overwritingOrAddingEvent + ", as there is " + "already an event stored with primary key '" + updatingData + "' at '" + queryName + "'");
                            fail = true;
                            break;
                        }
                    }
                }
            }
        }
    }
    foundEventChunk.reset();
    if (!fail) {
        if (doDeleteUpdate) {
            collectionExecutor.delete(overwritingOrAddingEvent, storeEvents);
            ComplexEventChunk<StreamEvent> toUpdateEventChunk = new ComplexEventChunk<StreamEvent>(false);
            while (foundEventChunk.hasNext()) {
                StreamEvent streamEvent = foundEventChunk.next();
                foundEventChunk.remove();
                // to make the chained state back to normal
                streamEvent.setNext(null);
                for (Map.Entry<Integer, ExpressionExecutor> entry : compiledUpdateSet.getExpressionExecutorMap().entrySet()) {
                    streamEvent.setOutputData(entry.getValue().execute(overwritingOrAddingEvent), entry.getKey());
                }
                toUpdateEventChunk.add(streamEvent);
            }
            storeEvents.add(toUpdateEventChunk);
        } else {
            while (foundEventChunk.hasNext()) {
                StreamEvent streamEvent = foundEventChunk.next();
                // to make the chained state back to normal
                streamEvent.setNext(null);
                for (Map.Entry<Integer, ExpressionExecutor> entry : compiledUpdateSet.getExpressionExecutorMap().entrySet()) {
                    streamEvent.setOutputData(entry.getValue().execute(overwritingOrAddingEvent), entry.getKey());
                }
            }
        }
    }
}
Also used : ExpressionExecutor(org.wso2.siddhi.core.executor.ExpressionExecutor) ComplexEventChunk(org.wso2.siddhi.core.event.ComplexEventChunk) StreamEvent(org.wso2.siddhi.core.event.stream.StreamEvent) PrimaryKeyReferenceHolder(org.wso2.siddhi.core.table.holder.PrimaryKeyReferenceHolder) Map(java.util.Map)

Example 13 with Fail

use of org.wso2.carbon.humantask.core.engine.commands.Fail in project wso2-synapse by wso2.

the class SynapseEventSourceTest method renewTest.

public void renewTest() {
    Date date = new Date(System.currentTimeMillis() + 3600000 * 2);
    Calendar cal = Calendar.getInstance();
    cal.setTime(date);
    String message = "<wse:Renew xmlns:wse=\"http://schemas.xmlsoap.org/ws/2004/08/eventing\">\n" + "   <wse:Expires>" + ConverterUtil.convertToString(cal) + "</wse:Expires>\n" + "</wse:Renew>";
    try {
        MessageContext msgCtx = createMessageContext(message, EventingConstants.WSE_RENEW);
        QName qname = new QName(EventingConstants.WSE_EVENTING_NS, EventingConstants.WSE_EN_IDENTIFIER, "wse");
        TestUtils.addSOAPHeaderBlock(msgCtx, qname, id);
        source.receive(msgCtx);
    } catch (Exception ignored) {
    }
    try {
        assertEquals(1, subMan.getSubscriptions().size());
        SynapseSubscription s = (SynapseSubscription) subMan.getSubscription(this.id);
        assertEquals(SUB_MAN_URL, s.getSubManUrl());
        assertEquals(ADDR_URL, s.getAddressUrl());
        assertEquals(FILTER_DIALECT, s.getFilterDialect());
        assertEquals(FILTER, s.getFilterValue());
        assertEquals(date, s.getExpires().getTime());
    } catch (EventException e) {
        fail("Eventing exception occured while accessing the subscription manager");
    }
}
Also used : EventException(org.wso2.eventing.exceptions.EventException) QName(javax.xml.namespace.QName) Calendar(java.util.Calendar) MessageContext(org.apache.axis2.context.MessageContext) Date(java.util.Date) EventException(org.wso2.eventing.exceptions.EventException)

Example 14 with Fail

use of org.wso2.carbon.humantask.core.engine.commands.Fail in project wso2-synapse by wso2.

the class SynapseEventSourceTest method createMessageContext.

private MessageContext createMessageContext(String payload, String action) {
    try {
        SynapseConfiguration synapseConfig = new SynapseConfiguration();
        AxisConfiguration axisConfig = new AxisConfiguration();
        synapseConfig.setAxisConfiguration(axisConfig);
        ConfigurationContext cfgCtx = new ConfigurationContext(axisConfig);
        SynapseEnvironment env = new Axis2SynapseEnvironment(cfgCtx, synapseConfig);
        axisConfig.addParameter(SynapseConstants.SYNAPSE_CONFIG, synapseConfig);
        axisConfig.addParameter(SynapseConstants.SYNAPSE_ENV, env);
        MessageContext msgCtx = TestUtils.getAxis2MessageContext(payload, null).getAxis2MessageContext();
        msgCtx.setConfigurationContext(cfgCtx);
        msgCtx.setTo(new EndpointReference(SUB_MAN_URL));
        msgCtx.setWSAAction(action);
        return msgCtx;
    } catch (Exception e) {
        fail();
    }
    return null;
}
Also used : AxisConfiguration(org.apache.axis2.engine.AxisConfiguration) ConfigurationContext(org.apache.axis2.context.ConfigurationContext) Axis2SynapseEnvironment(org.apache.synapse.core.axis2.Axis2SynapseEnvironment) Axis2SynapseEnvironment(org.apache.synapse.core.axis2.Axis2SynapseEnvironment) SynapseEnvironment(org.apache.synapse.core.SynapseEnvironment) MessageContext(org.apache.axis2.context.MessageContext) SynapseConfiguration(org.apache.synapse.config.SynapseConfiguration) EventException(org.wso2.eventing.exceptions.EventException) EndpointReference(org.apache.axis2.addressing.EndpointReference)

Example 15 with Fail

use of org.wso2.carbon.humantask.core.engine.commands.Fail in project wso2-synapse by wso2.

the class SynapseEventSourceTest method unsubscribeTest.

public void unsubscribeTest() {
    String message = "<wse:Unsubscribe xmlns:wse=\"http://schemas.xmlsoap.org/ws/2004/08/eventing\"/>";
    try {
        MessageContext msgCtx = createMessageContext(message, EventingConstants.WSE_UNSUBSCRIBE);
        QName qname = new QName(EventingConstants.WSE_EVENTING_NS, EventingConstants.WSE_EN_IDENTIFIER, "wse");
        TestUtils.addSOAPHeaderBlock(msgCtx, qname, id);
        source.receive(msgCtx);
    } catch (Exception ignored) {
    }
    try {
        assertEquals(0, subMan.getSubscriptions().size());
    } catch (EventException e) {
        fail("Eventing exception occured while accessing the subscription manager");
    }
}
Also used : EventException(org.wso2.eventing.exceptions.EventException) QName(javax.xml.namespace.QName) MessageContext(org.apache.axis2.context.MessageContext) EventException(org.wso2.eventing.exceptions.EventException)

Aggregations

ConfigurationContext (org.apache.axis2.context.ConfigurationContext)5 MessageContext (org.apache.axis2.context.MessageContext)5 IOException (java.io.IOException)4 EventException (org.wso2.eventing.exceptions.EventException)4 File (java.io.File)3 HashMap (java.util.HashMap)3 AxisFault (org.apache.axis2.AxisFault)3 APIManagementException (org.wso2.carbon.apimgt.core.exception.APIManagementException)3 Calendar (java.util.Calendar)2 Date (java.util.Date)2 QName (javax.xml.namespace.QName)2 AxisConfiguration (org.apache.axis2.engine.AxisConfiguration)2 Test (org.testng.annotations.Test)2 CarbonException (org.wso2.carbon.CarbonException)2 APIPublisher (org.wso2.carbon.apimgt.core.api.APIPublisher)2 DocumentInfo (org.wso2.carbon.apimgt.core.models.DocumentInfo)2 ErrorDTO (org.wso2.carbon.apimgt.rest.api.common.dto.ErrorDTO)2 SiddhiAppRuntime (org.wso2.siddhi.core.SiddhiAppRuntime)2 SiddhiManager (org.wso2.siddhi.core.SiddhiManager)2 ArrayList (java.util.ArrayList)1