Search in sources :

Example 1 with CommunicationConnectionFactory

use of com.alibaba.otter.shared.communication.core.impl.connection.CommunicationConnectionFactory in project otter by alibaba.

the class RmiConnectionTest method testPool_exhaust.

@Test
public void testPool_exhaust() {
    CommunicationConnectionFactory factory = new RmiCommunicationConnectionFactory();
    CommunicationConnectionFactory poolFactory = new CommunicationConnectionPoolFactory(factory);
    ((CommunicationConnectionPoolFactory) poolFactory).initial();
    CommunicationParam param = new CommunicationParam();
    param.setIp("127.0.0.1");
    param.setPort(1099);
    CommunicationRegistry.regist(PoolEventType.exhaust, new TestPoolService());
    ExecutorService executor = Executors.newCachedThreadPool();
    long start = System.currentTimeMillis();
    final CountDownLatch count = new CountDownLatch(11);
    for (int i = 0; i < 11; i++) {
        final CommunicationConnection connection = poolFactory.createConnection(param);
        final PoolEvent event = new PoolEvent(PoolEventType.exhaust);
        event.setSleep(1000);
        executor.submit(new Callable() {

            public Object call() throws Exception {
                try {
                    Object obj = connection.call(event);
                    count.countDown();
                    return obj;
                } finally {
                    connection.close();
                }
            }
        });
    }
    try {
        count.await();
    } catch (InterruptedException e) {
        want.fail();
    }
    long end = System.currentTimeMillis();
    want.number(end - start).isGe(1500L).isLe(2500L);
}
Also used : CommunicationConnectionPoolFactory(com.alibaba.otter.shared.communication.core.impl.connection.CommunicationConnectionPoolFactory) RmiCommunicationConnectionFactory(com.alibaba.otter.shared.communication.core.impl.rmi.RmiCommunicationConnectionFactory) CountDownLatch(java.util.concurrent.CountDownLatch) RmiCommunicationEndpoint(com.alibaba.otter.shared.communication.core.impl.rmi.RmiCommunicationEndpoint) Callable(java.util.concurrent.Callable) CommunicationConnection(com.alibaba.otter.shared.communication.core.impl.connection.CommunicationConnection) CommunicationParam(com.alibaba.otter.shared.communication.core.model.CommunicationParam) ExecutorService(java.util.concurrent.ExecutorService) RmiCommunicationConnectionFactory(com.alibaba.otter.shared.communication.core.impl.rmi.RmiCommunicationConnectionFactory) CommunicationConnectionFactory(com.alibaba.otter.shared.communication.core.impl.connection.CommunicationConnectionFactory) Test(org.testng.annotations.Test)

Example 2 with CommunicationConnectionFactory

use of com.alibaba.otter.shared.communication.core.impl.connection.CommunicationConnectionFactory in project otter by alibaba.

the class RmiConnectionTest method testSingle.

@Test
public void testSingle() {
    CommunicationConnectionFactory factory = new RmiCommunicationConnectionFactory();
    CommunicationParam param = new CommunicationParam();
    param.setIp("127.0.0.1");
    param.setPort(1099);
    CommunicationConnection connection = factory.createConnection(param);
    Object result = connection.call(new HeartEvent());
    want.object(result).notNull();
}
Also used : CommunicationConnection(com.alibaba.otter.shared.communication.core.impl.connection.CommunicationConnection) HeartEvent(com.alibaba.otter.shared.communication.core.model.heart.HeartEvent) CommunicationParam(com.alibaba.otter.shared.communication.core.model.CommunicationParam) RmiCommunicationConnectionFactory(com.alibaba.otter.shared.communication.core.impl.rmi.RmiCommunicationConnectionFactory) RmiCommunicationConnectionFactory(com.alibaba.otter.shared.communication.core.impl.rmi.RmiCommunicationConnectionFactory) CommunicationConnectionFactory(com.alibaba.otter.shared.communication.core.impl.connection.CommunicationConnectionFactory) Test(org.testng.annotations.Test)

Example 3 with CommunicationConnectionFactory

use of com.alibaba.otter.shared.communication.core.impl.connection.CommunicationConnectionFactory in project otter by alibaba.

the class RmiConnectionTest method testPool.

@Test
public void testPool() {
    CommunicationConnectionFactory factory = new RmiCommunicationConnectionFactory();
    CommunicationConnectionFactory poolFactory = new CommunicationConnectionPoolFactory(factory);
    ((CommunicationConnectionPoolFactory) poolFactory).initial();
    CommunicationParam param = new CommunicationParam();
    param.setIp("127.0.0.1");
    param.setPort(1099);
    CommunicationRegistry.regist(PoolEventType.pool, new TestPoolService());
    CommunicationConnection last = null;
    for (int i = 0; i < 11; i++) {
        CommunicationConnection connection = null;
        try {
            connection = poolFactory.createConnection(param);
            connection.call(new PoolEvent(PoolEventType.pool));
            last = connection;
            if (last != null) {
                // 检查链接是否是重用
                want.object(last).isEqualTo(connection);
            }
        } finally {
            connection.close();
        }
    }
}
Also used : CommunicationConnection(com.alibaba.otter.shared.communication.core.impl.connection.CommunicationConnection) CommunicationParam(com.alibaba.otter.shared.communication.core.model.CommunicationParam) CommunicationConnectionPoolFactory(com.alibaba.otter.shared.communication.core.impl.connection.CommunicationConnectionPoolFactory) RmiCommunicationConnectionFactory(com.alibaba.otter.shared.communication.core.impl.rmi.RmiCommunicationConnectionFactory) RmiCommunicationEndpoint(com.alibaba.otter.shared.communication.core.impl.rmi.RmiCommunicationEndpoint) RmiCommunicationConnectionFactory(com.alibaba.otter.shared.communication.core.impl.rmi.RmiCommunicationConnectionFactory) CommunicationConnectionFactory(com.alibaba.otter.shared.communication.core.impl.connection.CommunicationConnectionFactory) Test(org.testng.annotations.Test)

Example 4 with CommunicationConnectionFactory

use of com.alibaba.otter.shared.communication.core.impl.connection.CommunicationConnectionFactory in project otter by alibaba.

the class RmiCommunicationClientImpl method initial.

public void initial() {
    CommunicationConnectionFactory factory = null;
    if (poolable) {
        factory = new CommunicationConnectionPoolFactory(new RmiCommunicationConnectionFactory());
        ((CommunicationConnectionPoolFactory) factory).initial();
    } else {
        factory = new RmiCommunicationConnectionFactory();
    }
    super.setFactory(factory);
}
Also used : CommunicationConnectionPoolFactory(com.alibaba.otter.shared.communication.core.impl.connection.CommunicationConnectionPoolFactory) CommunicationConnectionFactory(com.alibaba.otter.shared.communication.core.impl.connection.CommunicationConnectionFactory)

Example 5 with CommunicationConnectionFactory

use of com.alibaba.otter.shared.communication.core.impl.connection.CommunicationConnectionFactory in project otter by alibaba.

the class DubboCommunicationTest method initial.

@BeforeClass
public void initial() {
    DubboCommunicationEndpoint endpoint2088 = new DubboCommunicationEndpoint(2088);
    endpoint2088.initial();
    DubboCommunicationEndpoint endpoint2089 = new DubboCommunicationEndpoint(2089);
    endpoint2089.initial();
    CommunicationConnectionFactory factory = new DubboCommunicationConnectionFactory();
    client = new DefaultCommunicationClientImpl(factory);
    client.initial();
}
Also used : DubboCommunicationConnectionFactory(com.alibaba.otter.shared.communication.core.impl.dubbo.DubboCommunicationConnectionFactory) DubboCommunicationEndpoint(com.alibaba.otter.shared.communication.core.impl.dubbo.DubboCommunicationEndpoint) DefaultCommunicationClientImpl(com.alibaba.otter.shared.communication.core.impl.DefaultCommunicationClientImpl) CommunicationConnectionFactory(com.alibaba.otter.shared.communication.core.impl.connection.CommunicationConnectionFactory) DubboCommunicationConnectionFactory(com.alibaba.otter.shared.communication.core.impl.dubbo.DubboCommunicationConnectionFactory) BeforeClass(org.testng.annotations.BeforeClass)

Aggregations

CommunicationConnectionFactory (com.alibaba.otter.shared.communication.core.impl.connection.CommunicationConnectionFactory)6 CommunicationConnection (com.alibaba.otter.shared.communication.core.impl.connection.CommunicationConnection)4 CommunicationParam (com.alibaba.otter.shared.communication.core.model.CommunicationParam)4 Test (org.testng.annotations.Test)4 CommunicationConnectionPoolFactory (com.alibaba.otter.shared.communication.core.impl.connection.CommunicationConnectionPoolFactory)3 RmiCommunicationConnectionFactory (com.alibaba.otter.shared.communication.core.impl.rmi.RmiCommunicationConnectionFactory)3 DubboCommunicationConnectionFactory (com.alibaba.otter.shared.communication.core.impl.dubbo.DubboCommunicationConnectionFactory)2 RmiCommunicationEndpoint (com.alibaba.otter.shared.communication.core.impl.rmi.RmiCommunicationEndpoint)2 HeartEvent (com.alibaba.otter.shared.communication.core.model.heart.HeartEvent)2 DefaultCommunicationClientImpl (com.alibaba.otter.shared.communication.core.impl.DefaultCommunicationClientImpl)1 DubboCommunicationEndpoint (com.alibaba.otter.shared.communication.core.impl.dubbo.DubboCommunicationEndpoint)1 Callable (java.util.concurrent.Callable)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 ExecutorService (java.util.concurrent.ExecutorService)1 BeforeClass (org.testng.annotations.BeforeClass)1