Search in sources :

Example 11 with Endpoint

use of org.apache.synapse.endpoints.Endpoint in project wso2-synapse by wso2.

the class WeightedRRLCAlgorithmTest method testNextEndpoint.

public void testNextEndpoint() {
    MessageContext messageContext = createMessageContext();
    LoadbalanceEndpoint endpoint = createLoadBalanceEndpoint();
    String[] firstTwoRoundsExpected = { "6", "6", "6", "6", "6", "6", "5", "5", "5", "5", "5", "3", "3", "3", "2", "2", "1", "6", "6", "6", "6", "6", "6", "5", "5", "5", "5", "5", "3", "3", "3", "2", "2", "1" };
    LoadbalanceAlgorithm algo = endpoint.getAlgorithm();
    String[] firstTwoRoundsResults = new String[34];
    for (int i = 0; i < 34; i++) {
        Endpoint epr = algo.getNextEndpoint(messageContext, null);
        if (epr instanceof AddressEndpoint) {
            firstTwoRoundsResults[i] = ((AddressEndpoint) epr).getProperty(WeightedRRLCAlgorithm.LB_WEIGHTED_RRLC_WEIGHT).getValue();
        }
    }
    for (int i = 0; i < 34; i++) {
        assertEquals(firstTwoRoundsExpected[i], firstTwoRoundsResults[i]);
    }
    String[] secondTwoRoundsExpected = { "6", "6", "6", "6", "5", "5", "5", "5", "5", "5", "5", "3", "3", "3", "3", "2", "2", "2", "2", "1", "1", "6", "6", "6", "6", "5", "5", "5", "5", "5", "5", "5", "3", "3" };
    String[] secondTwoRoundsResults = new String[34];
    for (int i = 0; i < 34; i++) {
        Endpoint epr = algo.getNextEndpoint(messageContext, null);
        if (epr instanceof AddressEndpoint) {
            secondTwoRoundsResults[i] = ((AddressEndpoint) epr).getProperty(WeightedRRLCAlgorithm.LB_WEIGHTED_RRLC_WEIGHT).getValue();
        }
    }
    for (int i = 0; i < 34; i++) {
        assertEquals(secondTwoRoundsExpected[i], secondTwoRoundsResults[i]);
    }
}
Also used : LoadbalanceEndpoint(org.apache.synapse.endpoints.LoadbalanceEndpoint) AddressEndpoint(org.apache.synapse.endpoints.AddressEndpoint) AddressEndpoint(org.apache.synapse.endpoints.AddressEndpoint) Endpoint(org.apache.synapse.endpoints.Endpoint) LoadbalanceEndpoint(org.apache.synapse.endpoints.LoadbalanceEndpoint) MessageContext(org.apache.synapse.MessageContext) Axis2MessageContext(org.apache.synapse.core.axis2.Axis2MessageContext) AddressEndpoint(org.apache.synapse.endpoints.AddressEndpoint) Endpoint(org.apache.synapse.endpoints.Endpoint) LoadbalanceEndpoint(org.apache.synapse.endpoints.LoadbalanceEndpoint)

Example 12 with Endpoint

use of org.apache.synapse.endpoints.Endpoint in project wso2-synapse by wso2.

the class SALSessionsTest method testUpdateWithOldSessionSameName.

/**
 * Test updating session with session id and old session where the old session id is same as current session id
 * @throws Exception
 */
@Test
public void testUpdateWithOldSessionSameName() throws Exception {
    BasicConfigurator.configure();
    SynapseConfiguration synapseConfiguration = new SynapseConfiguration();
    AxisConfiguration axisConfiguration = synapseConfiguration.getAxisConfiguration();
    ConfigurationContext cfgCtx = new ConfigurationContext(axisConfiguration);
    SynapseEnvironment synapseEnvironment = new Axis2SynapseEnvironment(cfgCtx, synapseConfiguration);
    Axis2MessageContext axis2MessageContext = new Axis2MessageContext(new org.apache.axis2.context.MessageContext(), synapseConfiguration, synapseEnvironment);
    MessageContext messageContext = axis2MessageContext;
    Endpoint endpoint = new AddressEndpoint();
    List<Endpoint> endpoints = new ArrayList<>();
    endpoints.add(endpoint);
    messageContext.setProperty(SynapseConstants.PROP_SAL_ENDPOINT_ENDPOINT_LIST, endpoints);
    SALSessions salSessions = SALSessions.getInstance();
    salSessions.initialize(false, cfgCtx);
    SessionInformation oldSessionInfo = new SessionInformation("testSession3", endpoints, 30000);
    messageContext.setProperty(SynapseConstants.PROP_SAL_CURRENT_SESSION_INFORMATION, oldSessionInfo);
    salSessions.updateSession(messageContext, "testSession3");
    SessionInformation sessionInformation = salSessions.getSession("testSession3");
    Assert.assertEquals("Session not updated!", "testSession3", sessionInformation.getId());
}
Also used : AxisConfiguration(org.apache.axis2.engine.AxisConfiguration) ConfigurationContext(org.apache.axis2.context.ConfigurationContext) Axis2SynapseEnvironment(org.apache.synapse.core.axis2.Axis2SynapseEnvironment) SynapseEnvironment(org.apache.synapse.core.SynapseEnvironment) ArrayList(java.util.ArrayList) SynapseConfiguration(org.apache.synapse.config.SynapseConfiguration) Axis2SynapseEnvironment(org.apache.synapse.core.axis2.Axis2SynapseEnvironment) AddressEndpoint(org.apache.synapse.endpoints.AddressEndpoint) AddressEndpoint(org.apache.synapse.endpoints.AddressEndpoint) Endpoint(org.apache.synapse.endpoints.Endpoint) MessageContext(org.apache.synapse.MessageContext) Axis2MessageContext(org.apache.synapse.core.axis2.Axis2MessageContext) Axis2MessageContext(org.apache.synapse.core.axis2.Axis2MessageContext) Test(org.junit.Test)

Example 13 with Endpoint

use of org.apache.synapse.endpoints.Endpoint in project wso2-synapse by wso2.

the class SALSessionsTest method testUpdateWithOldSession.

/**
 * Test updating session with session id and old session
 * @throws Exception
 */
@Test
public void testUpdateWithOldSession() throws Exception {
    BasicConfigurator.configure();
    SynapseConfiguration synapseConfiguration = new SynapseConfiguration();
    AxisConfiguration axisConfiguration = synapseConfiguration.getAxisConfiguration();
    ConfigurationContext cfgCtx = new ConfigurationContext(axisConfiguration);
    SynapseEnvironment synapseEnvironment = new Axis2SynapseEnvironment(cfgCtx, synapseConfiguration);
    Axis2MessageContext axis2MessageContext = new Axis2MessageContext(new org.apache.axis2.context.MessageContext(), synapseConfiguration, synapseEnvironment);
    MessageContext messageContext = axis2MessageContext;
    Endpoint endpoint = new AddressEndpoint();
    List<Endpoint> endpoints = new ArrayList<>();
    endpoints.add(endpoint);
    SALSessions salSessions = SALSessions.getInstance();
    salSessions.initialize(false, cfgCtx);
    SessionInformation oldSessionInfo = new SessionInformation("oldTestSession", endpoints, 30000);
    messageContext.setProperty(SynapseConstants.PROP_SAL_CURRENT_SESSION_INFORMATION, oldSessionInfo);
    salSessions.updateSession(messageContext, "testSession2");
    SessionInformation sessionInformation = salSessions.getSession("testSession2");
    Assert.assertEquals("Session not updated!", "testSession2", sessionInformation.getId());
}
Also used : AxisConfiguration(org.apache.axis2.engine.AxisConfiguration) ConfigurationContext(org.apache.axis2.context.ConfigurationContext) Axis2SynapseEnvironment(org.apache.synapse.core.axis2.Axis2SynapseEnvironment) SynapseEnvironment(org.apache.synapse.core.SynapseEnvironment) ArrayList(java.util.ArrayList) SynapseConfiguration(org.apache.synapse.config.SynapseConfiguration) Axis2SynapseEnvironment(org.apache.synapse.core.axis2.Axis2SynapseEnvironment) AddressEndpoint(org.apache.synapse.endpoints.AddressEndpoint) AddressEndpoint(org.apache.synapse.endpoints.AddressEndpoint) Endpoint(org.apache.synapse.endpoints.Endpoint) MessageContext(org.apache.synapse.MessageContext) Axis2MessageContext(org.apache.synapse.core.axis2.Axis2MessageContext) Axis2MessageContext(org.apache.synapse.core.axis2.Axis2MessageContext) Test(org.junit.Test)

Example 14 with Endpoint

use of org.apache.synapse.endpoints.Endpoint in project wso2-synapse by wso2.

the class SALSessionsTest method testUpdateWithId.

/**
 * Test updating session with session id
 * @throws Exception
 */
@Test
public void testUpdateWithId() throws Exception {
    BasicConfigurator.configure();
    SynapseConfiguration synapseConfiguration = new SynapseConfiguration();
    AxisConfiguration axisConfiguration = synapseConfiguration.getAxisConfiguration();
    ConfigurationContext cfgCtx = new ConfigurationContext(axisConfiguration);
    SynapseEnvironment synapseEnvironment = new Axis2SynapseEnvironment(cfgCtx, synapseConfiguration);
    Axis2MessageContext axis2MessageContext = new Axis2MessageContext(new org.apache.axis2.context.MessageContext(), synapseConfiguration, synapseEnvironment);
    MessageContext messageContext = axis2MessageContext;
    Endpoint endpoint = new AddressEndpoint();
    List<Endpoint> endpoints = new ArrayList<>();
    endpoints.add(endpoint);
    messageContext.setProperty(SynapseConstants.PROP_SAL_ENDPOINT_ENDPOINT_LIST, endpoints);
    SALSessions salSessions = SALSessions.getInstance();
    salSessions.initialize(false, cfgCtx);
    salSessions.updateSession(messageContext, "testSession");
    SessionInformation sessionInformation = salSessions.getSession("testSession");
    Assert.assertEquals("Session not updated!", "testSession", sessionInformation.getId());
}
Also used : AxisConfiguration(org.apache.axis2.engine.AxisConfiguration) ConfigurationContext(org.apache.axis2.context.ConfigurationContext) Axis2SynapseEnvironment(org.apache.synapse.core.axis2.Axis2SynapseEnvironment) SynapseEnvironment(org.apache.synapse.core.SynapseEnvironment) ArrayList(java.util.ArrayList) SynapseConfiguration(org.apache.synapse.config.SynapseConfiguration) Axis2SynapseEnvironment(org.apache.synapse.core.axis2.Axis2SynapseEnvironment) AddressEndpoint(org.apache.synapse.endpoints.AddressEndpoint) AddressEndpoint(org.apache.synapse.endpoints.AddressEndpoint) Endpoint(org.apache.synapse.endpoints.Endpoint) MessageContext(org.apache.synapse.MessageContext) Axis2MessageContext(org.apache.synapse.core.axis2.Axis2MessageContext) Axis2MessageContext(org.apache.synapse.core.axis2.Axis2MessageContext) Test(org.junit.Test)

Example 15 with Endpoint

use of org.apache.synapse.endpoints.Endpoint in project wso2-synapse by wso2.

the class SynapseObserverTest method testSimpleObserver.

public void testSimpleObserver() {
    SynapseConfiguration synapseConfig = new SynapseConfiguration();
    synapseConfig.setAxisConfiguration(new AxisConfiguration());
    synapseConfig.registerObserver(observer);
    Endpoint epr = new AddressEndpoint();
    epr.setName("endpoint1");
    synapseConfig.addEndpoint(epr.getName(), epr);
    assertItemAdded(epr.getName(), ENDPOINT);
    synapseConfig.removeEndpoint(epr.getName());
    assertItemRemoved(epr.getName(), ENDPOINT);
    SequenceMediator seq = new SequenceMediator();
    seq.setName("sequence1");
    synapseConfig.addSequence(seq.getName(), seq);
    assertItemAdded(seq.getName(), SEQUENCE);
    synapseConfig.removeSequence(seq.getName());
    assertItemRemoved(seq.getName(), SEQUENCE);
    TemplateMediator template = new TemplateMediator();
    template.setName("template1");
    synapseConfig.addSequenceTemplate(template.getName(), template);
    assertItemAdded(template.getName(), SEQUENCE_TEMPLATE);
    synapseConfig.removeSequenceTemplate(template.getName());
    assertItemRemoved(template.getName(), SEQUENCE_TEMPLATE);
    Entry entry = new Entry();
    entry.setKey("entry1");
    synapseConfig.addEntry(entry.getKey(), entry);
    assertItemAdded(entry.getKey(), ENTRY);
    synapseConfig.removeEntry(entry.getKey());
    assertItemRemoved(entry.getKey(), ENTRY);
    ProxyService proxy = new ProxyService("proxy1");
    synapseConfig.addProxyService(proxy.getName(), proxy);
    assertItemAdded(proxy.getName(), PROXY);
    synapseConfig.removeProxyService(proxy.getName());
    assertItemRemoved(proxy.getName(), PROXY);
    Startup startup = new StartUpController();
    startup.setName("startup1");
    synapseConfig.addStartup(startup);
    assertItemAdded(startup.getName(), STARTUP);
    synapseConfig.removeStartup(startup.getName());
    assertItemRemoved(startup.getName(), STARTUP);
    SynapseEventSource eventSrc = new SynapseEventSource("eventSrc1");
    synapseConfig.addEventSource(eventSrc.getName(), eventSrc);
    assertItemAdded(eventSrc.getName(), EVENT_SRC);
    synapseConfig.removeEventSource(eventSrc.getName());
    assertItemRemoved(eventSrc.getName(), EVENT_SRC);
    PriorityExecutor exec = new PriorityExecutor();
    exec.setName("exec1");
    synapseConfig.addPriorityExecutor(exec.getName(), exec);
    assertItemAdded(exec.getName(), EXECUTOR);
    synapseConfig.removeExecutor(exec.getName());
    assertItemRemoved(exec.getName(), EXECUTOR);
}
Also used : AxisConfiguration(org.apache.axis2.engine.AxisConfiguration) StartUpController(org.apache.synapse.startup.quartz.StartUpController) AddressEndpoint(org.apache.synapse.endpoints.AddressEndpoint) AddressEndpoint(org.apache.synapse.endpoints.AddressEndpoint) Endpoint(org.apache.synapse.endpoints.Endpoint) InboundEndpoint(org.apache.synapse.inbound.InboundEndpoint) TemplateMediator(org.apache.synapse.mediators.template.TemplateMediator) SynapseEventSource(org.apache.synapse.eventing.SynapseEventSource) ProxyService(org.apache.synapse.core.axis2.ProxyService) SequenceMediator(org.apache.synapse.mediators.base.SequenceMediator) PriorityExecutor(org.apache.synapse.commons.executors.PriorityExecutor) Startup(org.apache.synapse.Startup)

Aggregations

Endpoint (org.apache.synapse.endpoints.Endpoint)64 OMElement (org.apache.axiom.om.OMElement)22 SynapseException (org.apache.synapse.SynapseException)13 AddressEndpoint (org.apache.synapse.endpoints.AddressEndpoint)13 SequenceMediator (org.apache.synapse.mediators.base.SequenceMediator)11 ArrayList (java.util.ArrayList)10 MessageContext (org.apache.synapse.MessageContext)9 AxisConfiguration (org.apache.axis2.engine.AxisConfiguration)8 SynapseEnvironment (org.apache.synapse.core.SynapseEnvironment)8 Axis2MessageContext (org.apache.synapse.core.axis2.Axis2MessageContext)8 IndirectEndpoint (org.apache.synapse.endpoints.IndirectEndpoint)8 SALoadbalanceEndpoint (org.apache.synapse.endpoints.SALoadbalanceEndpoint)8 InboundEndpoint (org.apache.synapse.inbound.InboundEndpoint)8 OMAttribute (org.apache.axiom.om.OMAttribute)7 ConfigurationContext (org.apache.axis2.context.ConfigurationContext)7 SynapseConfiguration (org.apache.synapse.config.SynapseConfiguration)7 Axis2SynapseEnvironment (org.apache.synapse.core.axis2.Axis2SynapseEnvironment)7 QName (javax.xml.namespace.QName)6 AbstractEndpoint (org.apache.synapse.endpoints.AbstractEndpoint)6 DynamicLoadbalanceEndpoint (org.apache.synapse.endpoints.DynamicLoadbalanceEndpoint)6