"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "dso-l1/src/test/java/com/tc/object/DistributedObjectClientTest.java" between
terracotta-core-5.7.0.tar.gz and terracotta-core-5.7.1.tar.gz

About: Terracotta - Clustering technology for Java ("Network Attached Memory", "Distributed Cache"). Source code of the server (5.x) core components.

DistributedObjectClientTest.java  (terracotta-core-5.7.0):DistributedObjectClientTest.java  (terracotta-core-5.7.1)
skipping to change at line 28 skipping to change at line 28
*/ */
package com.tc.object; package com.tc.object;
import com.tc.lang.TCThreadGroup; import com.tc.lang.TCThreadGroup;
import com.tc.lang.TestThrowableHandler; import com.tc.lang.TestThrowableHandler;
import com.tc.net.core.ClearTextBufferManagerFactory; import com.tc.net.core.ClearTextBufferManagerFactory;
import com.tc.net.protocol.tcm.ClientMessageChannel; import com.tc.net.protocol.tcm.ClientMessageChannel;
import com.tc.net.protocol.tcm.CommunicationsManager; import com.tc.net.protocol.tcm.CommunicationsManager;
import com.tc.object.session.SessionProvider; import com.tc.object.session.SessionProvider;
import com.tc.util.Assert; import com.tc.util.Assert;
import com.tc.util.PortChooser;
import com.tc.net.core.ProductID; import com.tc.net.core.ProductID;
import java.net.InetSocketAddress; import java.net.InetSocketAddress;
import java.util.Collections; import java.util.Collections;
import java.util.Properties; import java.util.Properties;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import junit.framework.TestCase; import junit.framework.TestCase;
import org.mockito.Mockito; import org.mockito.Mockito;
import static com.tc.object.ClientBuilderFactory.CLIENT_BUILDER_TYPE; import static com.tc.object.ClientBuilderFactory.CLIENT_BUILDER_TYPE;
import static org.mockito.Mockito.when; import static org.mockito.Mockito.when;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.terracotta.connection.ConnectionPropertyNames; import org.terracotta.connection.ConnectionPropertyNames;
import org.terracotta.utilities.test.net.PortManager;
public class DistributedObjectClientTest extends TestCase { public class DistributedObjectClientTest extends TestCase {
public void testConnectionTimeout() throws Exception { public void testConnectionTimeout() throws Exception {
TCThreadGroup threadGroup = new TCThreadGroup(new TestThrowableHandler(Logge try (PortManager.PortRef portRef = PortManager.getInstance().reservePort())
rFactory.getLogger(DistributedObjectClient.class))); {
Properties connectionProperties = new Properties(); TCThreadGroup threadGroup = new TCThreadGroup(new TestThrowableHandler(Log
connectionProperties.put(CLIENT_BUILDER_TYPE, ClientBuilderFactory.ClientBui gerFactory.getLogger(DistributedObjectClient.class)));
lderType.TERRACOTTA); Properties connectionProperties = new Properties();
connectionProperties.put(ConnectionPropertyNames.CONNECTION_TYPE, ProductID. connectionProperties.put(CLIENT_BUILDER_TYPE, ClientBuilderFactory.ClientB
PERMANENT); uilderType.TERRACOTTA);
DistributedObjectClient client = connectionProperties.put(ConnectionPropertyNames.CONNECTION_TYPE, ProductI
new DistributedObjectClient( D.PERMANENT);
Collections.singleton(new InetSocketAddress("localhost", new PortCho DistributedObjectClient client =
oser().chooseRandomPort())), new DistributedObjectClient(
threadGroup, Collections.singleton(new InetSocketAddress("localhost", portRef.p
connectionProperties ort())),
); threadGroup,
client.start(); connectionProperties
Assert.assertTrue(threadGroup.activeCount() > 0); );
long start = System.currentTimeMillis(); client.start();
boolean connected = client.waitForConnection(10, TimeUnit.SECONDS); Assert.assertTrue(threadGroup.activeCount() > 0);
Assert.assertFalse(connected); long start = System.currentTimeMillis();
client.shutdown(); boolean connected = client.waitForConnection(10, TimeUnit.SECONDS);
Assert.assertTrue(threadGroup.activeCount() == 0); Assert.assertFalse(connected);
Assert.assertTrue(System.currentTimeMillis() - start, System.currentTimeMill client.shutdown();
is() - start < 15000); Assert.assertTrue(threadGroup.activeCount() == 0);
Assert.assertTrue(System.currentTimeMillis() - start, System.currentTimeMi
llis() - start < 15000);
}
int count = Thread.activeCount(); int count = Thread.activeCount();
System.out.println("active threads:" + count); System.out.println("active threads:" + count);
Thread[] t = new Thread[count]; Thread[] t = new Thread[count];
Thread.enumerate(t); Thread.enumerate(t);
for (Thread z : t) { for (Thread z : t) {
if (z != null ) { if (z != null ) {
System.out.println(z.getName()); System.out.println(z.getName());
} }
} }
} }
public void testFatalError() throws Exception { public void testFatalError() throws Exception {
TCThreadGroup threadGroup = new TCThreadGroup(new TestThrowableHandler(Logge try (PortManager.PortRef portRef = PortManager.getInstance().reservePort())
rFactory.getLogger(DistributedObjectClient.class))); {
Properties connectionProperties = new Properties(); TCThreadGroup threadGroup = new TCThreadGroup(new TestThrowableHandler(Log
connectionProperties.put(ConnectionPropertyNames.CONNECTION_TYPE, ProductID. gerFactory.getLogger(DistributedObjectClient.class)));
PERMANENT); Properties connectionProperties = new Properties();
ClientBuilder builder = new StandardClientBuilder(connectionProperties, new connectionProperties.put(ConnectionPropertyNames.CONNECTION_TYPE, ProductI
ClearTextBufferManagerFactory()) { D.PERMANENT);
@Override ClientBuilder builder = new StandardClientBuilder(connectionProperties, ne
public ClientMessageChannel createClientMessageChannel(CommunicationsManag w ClearTextBufferManagerFactory()) {
er commMgr, SessionProvider sessionProvider, int socketConnectTimeout) { @Override
ClientMessageChannel channel = Mockito.mock(ClientMessageChannel.class); public ClientMessageChannel createClientMessageChannel(CommunicationsMan
try { ager commMgr, SessionProvider sessionProvider, int socketConnectTimeout) {
Mockito.when(channel.open(Mockito.anyCollection())).thenThrow(new Runt ClientMessageChannel channel = Mockito.mock(ClientMessageChannel.class
imeException("bad connection")); );
} catch (Exception exp) { try {
Mockito.when(channel.open(Mockito.anyCollection())).thenThrow(new Ru
ntimeException("bad connection"));
} catch (Exception exp) {
}
when(channel.getProductID()).thenReturn(ProductID.PERMANENT);
return channel;
} }
when(channel.getProductID()).thenReturn(ProductID.PERMANENT); };
return channel;
}
};
DistributedObjectClient client = new DistributedObjectClient( DistributedObjectClient client = new DistributedObjectClient(
Collections.singleton(InetSocketAddress.createUnresolved("localhost", ne Collections.singleton(InetSocketAddress.createUnresolved("localhost",
w PortChooser().chooseRandomPort())), portRef.port())),
builder, builder,
threadGroup, threadGroup,
null, null,
null, null,
false false
); );
client.start(); client.start();
Assert.assertTrue(threadGroup.activeCount() > 0); Assert.assertTrue(threadGroup.activeCount() > 0);
long start = System.currentTimeMillis(); long start = System.currentTimeMillis();
try { try {
client.waitForConnection(10, TimeUnit.SECONDS); client.waitForConnection(10, TimeUnit.SECONDS);
Assert.fail(); Assert.fail();
} catch (RuntimeException exp) { } catch (RuntimeException exp) {
// expected // expected
Assert.assertNotNull(exp); Assert.assertNotNull(exp);
Assert.assertEquals(exp.getCause().getMessage(), "bad connection"); Assert.assertEquals(exp.getCause().getMessage(), "bad connection");
}
client.shutdown();
Assert.assertTrue(threadGroup.activeCount() == 0);
Assert.assertTrue(System.currentTimeMillis() - start < 11000);
} }
client.shutdown();
Assert.assertTrue(threadGroup.activeCount() == 0);
Assert.assertTrue(System.currentTimeMillis() - start < 11000);
int count = Thread.activeCount(); int count = Thread.activeCount();
System.out.println("active threads:" + count); System.out.println("active threads:" + count);
Thread[] t = new Thread[count]; Thread[] t = new Thread[count];
Thread.enumerate(t); Thread.enumerate(t);
for (Thread z : t) { for (Thread z : t) {
if (z != null ) { if (z != null ) {
System.out.println(z.getName()); System.out.println(z.getName());
} }
} }
} }
 End of changes. 7 change blocks. 
66 lines changed or deleted 73 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)