synapse-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Supun Kamburugamuva <supu...@gmail.com>
Subject Re: svn commit: r952839 - in /synapse/trunk/java/modules/core/src/test/java/org/apache/synapse/endpoints: ./ algorithms/ algorithms/WeightedRRLCAlgorithmTest.java
Date Wed, 09 Jun 2010 04:59:15 GMT
Fixed.

Thanks,
Supun..

On Wed, Jun 9, 2010 at 12:24 AM, Hiranya Jayathilaka
<hiranya911@gmail.com>wrote:

> Hi Supun,
>
> This test has failed in Hudson with the following error:
> Error Message
>
> expected:&lt;21&gt; but was:&lt;17&gt;
>
> Stacktrace
>
> junit.framework.AssertionFailedError: expected:&21& but was:&17&
> 	at junit.framework.Assert.fail(Assert.java:47)
> 	at junit.framework.Assert.failNotEquals(Assert.java:280)
> 	at junit.framework.Assert.assertEquals(Assert.java:64)
> 	at junit.framework.Assert.assertEquals(Assert.java:198)
> 	at junit.framework.Assert.assertEquals(Assert.java:204)
> 	at org.apache.synapse.endpoints.algorithms.WeightedRRLCAlgorithmTest.testInitialization(WeightedRRLCAlgorithmTest.java:63)
> 	at org.apache.synapse.endpoints.algorithms.WeightedRRLCAlgorithmTest.testInitialization(WeightedRRLCAlgorithmTest.java:63)
> 	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
> 	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
> 	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
> 	at java.lang.reflect.Method.invoke(Method.java:592)
> 	at junit.framework.TestCase.runTest(TestCase.java:164)
> 	at junit.framework.TestCase.runBare(TestCase.java:130)
> 	at junit.framework.TestResult$1.protect(TestResult.java:106)
> 	at junit.framework.TestResult.runProtected(TestResult.java:124)
> 	at junit.framework.TestResult.run(TestResult.java:109)
> 	at junit.framework.TestCase.run(TestCase.java:120)
> 	at junit.framework.TestSuite.runTest(TestSuite.java:230)
> 	at junit.framework.TestSuite.run(TestSuite.java:225)
> 	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
> 	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
> 	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
> 	at java.lang.reflect.Method.invoke(Method.java:592)
> 	at org.apache.maven.surefire.junit.JUnitTestSet.execute(JUnitTestSet.java:213)
> 	at org.apache.maven.surefire.suite.AbstractDirectoryTestSuite.executeTestSet(AbstractDirectoryTestSuite.java:138)
> 	at org.apache.maven.surefire.suite.AbstractDirectoryTestSuite.execute(AbstractDirectoryTestSuite.java:163)
> 	at org.apache.maven.surefire.Surefire.run(Surefire.java:84)
> 	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
> 	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
> 	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
> 	at java.lang.reflect.Method.invoke(Method.java:592)
> 	at org.apache.maven.surefire.booter.SurefireBooter.runSuitesInProcess(SurefireBooter.java:244)
> 	at org.apache.maven.surefire.booter.SurefireBooter.main(SurefireBooter.java:814)
>
>
> Please have a look.
>
> Thanks,
> Hiranya
>
> On Wed, Jun 9, 2010 at 3:35 AM, <supun@apache.org> wrote:
>
>> Author: supun
>> Date: Tue Jun  8 22:05:25 2010
>> New Revision: 952839
>>
>> URL: http://svn.apache.org/viewvc?rev=952839&view=rev
>> Log:
>> adding a test case for the Weighted Round Robin Least coneection algorithm
>>
>> Added:
>>
>>  synapse/trunk/java/modules/core/src/test/java/org/apache/synapse/endpoints/
>>
>>  synapse/trunk/java/modules/core/src/test/java/org/apache/synapse/endpoints/algorithms/
>>
>>  synapse/trunk/java/modules/core/src/test/java/org/apache/synapse/endpoints/algorithms/WeightedRRLCAlgorithmTest.java
>>
>> Added:
>> synapse/trunk/java/modules/core/src/test/java/org/apache/synapse/endpoints/algorithms/WeightedRRLCAlgorithmTest.java
>> URL:
>> http://svn.apache.org/viewvc/synapse/trunk/java/modules/core/src/test/java/org/apache/synapse/endpoints/algorithms/WeightedRRLCAlgorithmTest.java?rev=952839&view=auto
>>
>> ==============================================================================
>> ---
>> synapse/trunk/java/modules/core/src/test/java/org/apache/synapse/endpoints/algorithms/WeightedRRLCAlgorithmTest.java
>> (added)
>> +++
>> synapse/trunk/java/modules/core/src/test/java/org/apache/synapse/endpoints/algorithms/WeightedRRLCAlgorithmTest.java
>> Tue Jun  8 22:05:25 2010
>> @@ -0,0 +1,173 @@
>> +/*
>> + *  Licensed to the Apache Software Foundation (ASF) under one
>> + *  or more contributor license agreements.  See the NOTICE file
>> + *  distributed with this work for additional information
>> + *  regarding copyright ownership.  The ASF licenses this file
>> + *  to you under the Apache License, Version 2.0 (the
>> + *  "License"); you may not use this file except in compliance
>> + *  with the License.  You may obtain a copy of the License at
>> + *
>> + *   http://www.apache.org/licenses/LICENSE-2.0
>> + *
>> + *  Unless required by applicable law or agreed to in writing,
>> + *  software distributed under the License is distributed on an
>> + *   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
>> + *  KIND, either express or implied.  See the License for the
>> + *  specific language governing permissions and limitations
>> + *  under the License.
>> + */
>> +
>> +package org.apache.synapse.endpoints.algorithms;
>> +
>> +import junit.framework.TestCase;
>> +
>> +import java.util.Map;
>> +import java.util.HashMap;
>> +import java.util.List;
>> +import java.util.ArrayList;
>> +import java.util.concurrent.atomic.AtomicInteger;
>> +
>> +import org.apache.synapse.endpoints.Endpoint;
>> +import org.apache.synapse.endpoints.AddressEndpoint;
>> +import org.apache.synapse.endpoints.EndpointDefinition;
>> +import org.apache.synapse.endpoints.LoadbalanceEndpoint;
>> +import org.apache.synapse.mediators.MediatorProperty;
>> +import org.apache.synapse.MessageContext;
>> +import org.apache.synapse.config.SynapseConfiguration;
>> +import org.apache.synapse.core.axis2.Axis2MessageContext;
>> +import org.apache.synapse.core.axis2.Axis2SynapseEnvironment;
>> +import org.apache.synapse.core.SynapseEnvironment;
>> +import org.apache.axis2.context.ConfigurationContext;
>> +import org.apache.axis2.engine.AxisConfiguration;
>> +
>> +public class WeightedRRLCAlgorithmTest extends TestCase {
>> +    private String[] hosts = {"localhost:9000", "localhost:9001",
>> +                              "localhost:9002", "localhost:9003",
>> +                              "localhost:9004"};
>> +
>> +    private String[] weights = {"6", "5", "3", "2", "1"};
>> +
>> +    private AtomicInteger[] connections = {
>> +            new AtomicInteger(18), new AtomicInteger(5),
>> +            new AtomicInteger(4), new AtomicInteger(2),
>> +            new AtomicInteger(1)};
>> +
>> +    public void testInitialization () {
>> +        LoadbalanceEndpoint endpoint = createLoadBalanceEndpoint();
>> +
>> +        LoadbalanceAlgorithm algo = endpoint.getAlgorithm();
>> +
>> +        assert algo instanceof WeightedRRLCAlgorithm;
>> +        WeightedRRLCAlgorithm algorithm = (WeightedRRLCAlgorithm) algo;
>> +
>> +        assertEquals(10 + 5 + 3 + 2 + 1, algorithm.getTotalWeight());
>> +        assertEquals(0, algorithm.getTotalConnections());
>> +        assertEquals(0, algorithm.getEndpointCursor());
>> +        assertEquals(2, algorithm.getRoundsPerRecalculation());
>> +    }
>> +
>> +    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]);
>> +        }
>> +    }
>> +
>> +    private LoadbalanceEndpoint createLoadBalanceEndpoint() {
>> +        LoadbalanceEndpoint loadbalanceEndpoint = new
>> LoadbalanceEndpoint();
>> +        List<Endpoint> endpoints = createEndpoints();
>> +        WeightedRRLCAlgorithm algorithm = new WeightedRRLCAlgorithm();
>> +
>> +        MediatorProperty property = new MediatorProperty();
>> +
>>  property.setName(WeightedRRLCAlgorithm.LB_WEIGHTED_RRLC_ROUNDS_PER_RECAL);
>> +        property.setValue("2");
>> +        loadbalanceEndpoint.addProperty(property);
>> +
>> +        algorithm.setEndpoints(endpoints);
>> +        algorithm.setLoadBalanceEndpoint(loadbalanceEndpoint);
>> +
>> +        loadbalanceEndpoint.setChildren(endpoints);
>> +        loadbalanceEndpoint.setAlgorithm(algorithm);
>> +
>> +        SynapseEnvironment env = new Axis2SynapseEnvironment(
>> +                new ConfigurationContext(new AxisConfiguration()), new
>> SynapseConfiguration());
>> +        loadbalanceEndpoint.init(env);
>> +        return loadbalanceEndpoint;
>> +    }
>> +
>> +    private MessageContext createMessageContext() {
>> +        org.apache.axis2.context.MessageContext axisMessageContext =
>> +                new org.apache.axis2.context.MessageContext();
>> +
>> +        MessageContext synapseMessageContext =
>> +                new Axis2MessageContext(axisMessageContext, null, null);
>> +
>> +        axisMessageContext.setProperty("OPEN_CONNNECTIONS_MAP",
>> createMap());
>> +
>> +        return synapseMessageContext;
>> +    }
>> +
>> +    private Map<String, AtomicInteger> createMap() {
>> +        Map<String, AtomicInteger> connectionsMap = new HashMap<String,
>> AtomicInteger>();
>> +        for (int i = 0; i < hosts.length; i++) {
>> +            connectionsMap.put(hosts[i], connections[i]);
>> +        }
>> +        return connectionsMap;
>> +    }
>> +
>> +
>> +    private List<Endpoint> createEndpoints() {
>> +        List<Endpoint> endpoints = new ArrayList<Endpoint>();
>> +        for (int i = 0; i < hosts.length; i++) {
>> +            AddressEndpoint addressEndpoint = new AddressEndpoint();
>> +
>> +            EndpointDefinition definition = new EndpointDefinition();
>> +            definition.setAddress("http://" + hosts[i] + "/");
>> +            addressEndpoint.setDefinition(definition);
>> +
>> +            MediatorProperty property = new MediatorProperty();
>> +
>>  property.setName(WeightedRRLCAlgorithm.LB_WEIGHTED_RRLC_WEIGHT);
>> +            property.setValue(weights[i]);
>> +            addressEndpoint.addProperty(property);
>> +
>> +            endpoints.add(addressEndpoint);
>> +        }
>> +
>> +        return endpoints;
>> +    }
>> +}
>>
>>
>>
>
>
> --
> Hiranya Jayathilaka
> Senior Software Engineer;
> WSO2 Inc.;  http://wso2.org
> E-mail: hiranya@wso2.com;  Mobile: +94 77 633 3491
> Blog: http://techfeast-hiranya.blogspot.com
>



-- 
Software Engineer, WSO2 Inc
http://wso2.org
supunk.blogspot.com

Mime
View raw message