"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "common/src/test/java/com/tc/net/protocol/tcm/LazyHandshakeTest.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.

LazyHandshakeTest.java  (terracotta-core-5.7.0):LazyHandshakeTest.java  (terracotta-core-5.7.1)
skipping to change at line 22 skipping to change at line 22
* *
* The Covered Software is Terracotta Core. * The Covered Software is Terracotta Core.
* *
* The Initial Developer of the Covered Software is * The Initial Developer of the Covered Software is
* Terracotta, Inc., a Software AG company * Terracotta, Inc., a Software AG company
* *
*/ */
package com.tc.net.protocol.tcm; package com.tc.net.protocol.tcm;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.terracotta.utilities.test.net.PortManager;
import com.tc.lang.TCThreadGroup; import com.tc.lang.TCThreadGroup;
import com.tc.lang.ThrowableHandlerImpl; import com.tc.lang.ThrowableHandlerImpl;
import com.tc.net.CommStackMismatchException; import com.tc.net.CommStackMismatchException;
import com.tc.net.MaxConnectionsExceededException; import com.tc.net.MaxConnectionsExceededException;
import com.tc.net.TCSocketAddress; import com.tc.net.TCSocketAddress;
import com.tc.net.basic.BasicConnectionManager; import com.tc.net.basic.BasicConnectionManager;
import com.tc.net.core.ClearTextBufferManagerFactory; import com.tc.net.core.ClearTextBufferManagerFactory;
import com.tc.net.core.TCConnectionManager; import com.tc.net.core.TCConnectionManager;
import com.tc.net.core.TCConnectionManagerImpl; import com.tc.net.core.TCConnectionManagerImpl;
skipping to change at line 44 skipping to change at line 45
import com.tc.net.protocol.transport.ConnectionID; import com.tc.net.protocol.transport.ConnectionID;
import com.tc.net.protocol.transport.DefaultConnectionIdFactory; import com.tc.net.protocol.transport.DefaultConnectionIdFactory;
import com.tc.net.protocol.transport.DisabledHealthCheckerConfigImpl; import com.tc.net.protocol.transport.DisabledHealthCheckerConfigImpl;
import com.tc.net.protocol.transport.MessageTransport; import com.tc.net.protocol.transport.MessageTransport;
import com.tc.net.protocol.transport.NullConnectionPolicy; import com.tc.net.protocol.transport.NullConnectionPolicy;
import com.tc.net.proxy.TCPProxy; import com.tc.net.proxy.TCPProxy;
import com.tc.object.session.NullSessionManager; import com.tc.object.session.NullSessionManager;
import com.tc.net.core.ProductID; import com.tc.net.core.ProductID;
import com.tc.test.TCTestCase; import com.tc.test.TCTestCase;
import com.tc.util.Assert; import com.tc.util.Assert;
import com.tc.util.PortChooser;
import com.tc.util.TCTimeoutException; import com.tc.util.TCTimeoutException;
import com.tc.util.concurrent.ThreadUtil; import com.tc.util.concurrent.ThreadUtil;
import java.io.IOException; import java.io.IOException;
import java.net.InetSocketAddress; import java.net.InetSocketAddress;
import java.net.UnknownHostException; import java.net.UnknownHostException;
import java.util.HashSet; import java.util.HashSet;
/** /**
* CDV-1320: Whenever there is a Transport Handshake timeout(10secs), the connec ted client transport is left as is and a * CDV-1320: Whenever there is a Transport Handshake timeout(10secs), the connec ted client transport is left as is and a
skipping to change at line 72 skipping to change at line 72
public class LazyHandshakeTest extends TCTestCase { public class LazyHandshakeTest extends TCTestCase {
// proxy timeouts : one-way // proxy timeouts : one-way
private static final long PROXY_SYNACK_DELAY = ClientMessageTransport.TRAN SPORT_HANDSHAKE_SYNACK_TIMEOUT; private static final long PROXY_SYNACK_DELAY = ClientMessageTransport.TRAN SPORT_HANDSHAKE_SYNACK_TIMEOUT;
private static final int CLIENT_COUNT = 3; private static final int CLIENT_COUNT = 3;
private TCConnectionManager serverConn; private TCConnectionManager serverConn;
private TCConnectionManager clientConn; private TCConnectionManager clientConn;
private CommunicationsManager serverComms; private CommunicationsManager serverComms;
private CommunicationsManager clientComms; private CommunicationsManager clientComms;
private PortChooser pc;
private TCPProxy proxy; private TCPProxy proxy;
private int proxyPort;
private InetSocketAddress serverAddress; private InetSocketAddress serverAddress;
private NetworkListener listener; private NetworkListener listener;
private final ClientMessageChannel channel[] = new ClientMessageChan nel[CLIENT_COUNT]; private final ClientMessageChannel channel[] = new ClientMessageChan nel[CLIENT_COUNT];
private int currentClient = 0; private int currentClient = 0;
@Override @Override
protected void setUp() throws Exception { protected void setUp() throws Exception {
super.setUp(); super.setUp();
} }
private void lazySetUp() { private void lazySetUp(int proxyPort) {
pc = new PortChooser();
serverConn = new TCConnectionManagerImpl("Server-Connections", 0, new Disab ledHealthCheckerConfigImpl(), new ClearTextBufferManagerFactory()); serverConn = new TCConnectionManagerImpl("Server-Connections", 0, new Disab ledHealthCheckerConfigImpl(), new ClearTextBufferManagerFactory());
clientConn = new BasicConnectionManager("", new ClearTextBufferManagerFactor y()); clientConn = new BasicConnectionManager("", new ClearTextBufferManagerFactor y());
serverComms = new CommunicationsManagerImpl(new NullMessageMonitor(), new Pl ainNetworkStackHarnessFactory(), serverComms = new CommunicationsManagerImpl(new NullMessageMonitor(), new Pl ainNetworkStackHarnessFactory(),
serverConn, serverConn,
new NullConnectionPolicy()); new NullConnectionPolicy());
clientComms = new CommunicationsManagerImpl(new NullMessageMonitor(), new Pl ainNetworkStackHarnessFactory(), clientComms = new CommunicationsManagerImpl(new NullMessageMonitor(), new Pl ainNetworkStackHarnessFactory(),
clientConn, clientConn,
new NullConnectionPolicy()); new NullConnectionPolicy());
listener = serverComms.createListener(new TCSocketAddress(0), true, listener = serverComms.createListener(new TCSocketAddress(0), true,
new DefaultConnectionIdFactory(), (Mes sageTransport t)->true); new DefaultConnectionIdFactory(), (Mes sageTransport t)->true);
try { try {
listener.start(new HashSet<ConnectionID>()); listener.start(new HashSet<ConnectionID>());
} catch (Exception e) { } catch (Exception e) {
System.out.println("lsnr Excep"); System.out.println("lsnr Excep");
} }
proxyPort = pc.chooseRandomPort();
proxy = new TCPProxy(proxyPort, listener.getBindAddress(), listener.getBindP ort(), PROXY_SYNACK_DELAY, false, null); proxy = new TCPProxy(proxyPort, listener.getBindAddress(), listener.getBindP ort(), PROXY_SYNACK_DELAY, false, null);
serverAddress = InetSocketAddress.createUnresolved(listener.getBindAddress() .getHostAddress(), proxyPort); serverAddress = InetSocketAddress.createUnresolved(listener.getBindAddress() .getHostAddress(), proxyPort);
try { try {
proxy.start(); proxy.start();
} catch (Exception e) { } catch (Exception e) {
System.out.println("proxy lsnr Excep"); System.out.println("proxy lsnr Excep");
} }
} }
private ClientMessageChannel createClientMessageChannel() { private ClientMessageChannel createClientMessageChannel() {
return clientComms return clientComms
.createClientChannel(ProductID.STRIPE, new NullSessionManager(), .createClientChannel(ProductID.STRIPE, new NullSessionManager(),
(int) PROXY_SYNACK_DELAY); (int) PROXY_SYNACK_DELAY);
} }
@Override @Override
protected void tearDown() throws Exception { protected void tearDown() throws Exception {
try {
listener.stop(5000);
} catch (TCTimeoutException e) {
// ignored
}
clientComms.shutdown(); clientComms.shutdown();
serverComms.shutdown(); serverComms.shutdown();
clientConn.shutdown(); clientConn.shutdown();
serverConn.shutdown(); serverConn.shutdown();
super.tearDown(); super.tearDown();
} }
public void testLazyHandshake() { public void testLazyHandshake() {
TCThreadGroup threadGroup = new TCThreadGroup(new ThrowableHandlerImpl(Logge rFactory.getLogger(this.getClass()))); TCThreadGroup threadGroup = new TCThreadGroup(new ThrowableHandlerImpl(Logge rFactory.getLogger(this.getClass())));
// imitating TCGroupManager implementation of StaticMemberDiscovery on hands hake timeouts // imitating TCGroupManager implementation of StaticMemberDiscovery on hands hake timeouts
Thread lazyThread = new Thread(threadGroup, new Runnable() { try (PortManager.PortRef portRef = PortManager.getInstance().reservePort())
@Override {
public void run() { Thread lazyThread = new Thread(threadGroup, new Runnable() {
lazySetUp(); @Override
handshaker(); public void run() {
lazySetUp(portRef.port());
handshaker();
}
});
try {
lazyThread.start();
try {
lazyThread.join();
} catch (InterruptedException e) {
System.out.println("Received the UNexpected exception: " + e);
}
ThreadUtil.reallySleep(3 * PROXY_SYNACK_DELAY);
Assert.eval((channel[0].getConnectCount() + channel[1].getConnectCount()
+ channel[2].getConnectCount()) == 0);
} finally {
if (proxy != null) {
proxy.stop();
}
} }
});
lazyThread.start();
try {
lazyThread.join();
} catch (InterruptedException e) {
System.out.println("Received the UNexpected exception: " + e);
} }
ThreadUtil.reallySleep(3 * PROXY_SYNACK_DELAY);
Assert.eval((channel[0].getConnectCount() + channel[1].getConnectCount() + c
hannel[2].getConnectCount()) == 0);
} }
private void handshaker() { private void handshaker() {
for (currentClient = 0; currentClient < 3; currentClient++) { for (currentClient = 0; currentClient < 3; currentClient++) {
System.out.println("Connecting to peer node. Attempt :" + currentClient); System.out.println("Connecting to peer node. Attempt :" + currentClient);
Thread t = new Thread(new Runnable() { Thread t = new Thread(new Runnable() {
@Override @Override
public void run() { public void run() {
channel[currentClient] = createClientMessageChannel(); channel[currentClient] = createClientMessageChannel();
try { try {
 End of changes. 10 change blocks. 
22 lines changed or deleted 31 lines changed or added

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