use of com.alibaba.otter.shared.communication.core.impl.connection.CommunicationConnectionPoolFactory 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);
}
use of com.alibaba.otter.shared.communication.core.impl.connection.CommunicationConnectionPoolFactory in project otter by alibaba.
the class RmiCommunicationTest method initial.
@BeforeClass
public void initial() {
RmiCommunicationEndpoint endpoint1099 = new RmiCommunicationEndpoint(1099);
endpoint1099.setAlwaysCreateRegistry(false);
endpoint1099.initial();
RmiCommunicationEndpoint endpoint1098 = new RmiCommunicationEndpoint(1098);
endpoint1098.setAlwaysCreateRegistry(false);
endpoint1098.initial();
CommunicationConnectionPoolFactory factory = new CommunicationConnectionPoolFactory(new RmiCommunicationConnectionFactory());
factory.initial();
client = new DefaultCommunicationClientImpl(factory);
client.initial();
}
use of com.alibaba.otter.shared.communication.core.impl.connection.CommunicationConnectionPoolFactory 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();
}
}
}
use of com.alibaba.otter.shared.communication.core.impl.connection.CommunicationConnectionPoolFactory 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);
}
Aggregations