"Fossies" - the Fresh Open Source Software Archive  

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

BasicConnectionTest.java  (terracotta-core-5.7.0):BasicConnectionTest.java  (terracotta-core-5.7.1)
skipping to change at line 31 skipping to change at line 31
import com.tc.bytes.TCByteBuffer; import com.tc.bytes.TCByteBuffer;
import com.tc.net.TCSocketAddress; import com.tc.net.TCSocketAddress;
import com.tc.net.core.BufferManager; import com.tc.net.core.BufferManager;
import com.tc.net.core.BufferManagerFactory; import com.tc.net.core.BufferManagerFactory;
import com.tc.net.core.TCConnection; import com.tc.net.core.TCConnection;
import com.tc.net.core.event.TCConnectionEvent; import com.tc.net.core.event.TCConnectionEvent;
import com.tc.net.core.event.TCConnectionEventListener; import com.tc.net.core.event.TCConnectionEventListener;
import com.tc.net.protocol.TCProtocolAdaptor; import com.tc.net.protocol.TCProtocolAdaptor;
import com.tc.net.protocol.transport.WireProtocolHeader; import com.tc.net.protocol.transport.WireProtocolHeader;
import com.tc.net.protocol.transport.WireProtocolMessage; import com.tc.net.protocol.transport.WireProtocolMessage;
import com.tc.util.PortChooser;
import java.io.IOException; import java.io.IOException;
import java.net.ServerSocket; import java.net.ServerSocket;
import java.net.Socket; import java.net.Socket;
import java.nio.channels.SocketChannel; import java.nio.channels.SocketChannel;
import java.util.function.Function; import java.util.function.Function;
import org.junit.After; import org.junit.After;
import org.junit.AfterClass; import org.junit.AfterClass;
import org.junit.Before; import org.junit.Before;
import org.junit.BeforeClass; import org.junit.BeforeClass;
import org.junit.Test; import org.junit.Test;
import org.terracotta.utilities.test.net.PortManager;
import static org.junit.Assert.*; import static org.junit.Assert.*;
import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.mock; import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify; import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when; import static org.mockito.Mockito.when;
/** /**
* *
*/ */
public class BasicConnectionTest { public class BasicConnectionTest {
skipping to change at line 73 skipping to change at line 74
@Before @Before
public void setUp() { public void setUp() {
} }
@After @After
public void tearDown() { public void tearDown() {
} }
private ServerSocket openServerSocket() { private ServerSocket openServerSocket(int port) {
int port = 0;
ServerSocket server = null; ServerSocket server = null;
while (server == null) { while (server == null) {
port = new PortChooser().chooseRandomPort();
try { try {
server = new ServerSocket(port); server = new ServerSocket(port);
} catch (IOException ioe) { } catch (IOException ioe) {
// ignored
} }
} }
return server; return server;
} }
/** /**
* Test of getConnectTime method, of class BasicConnection. * Test of getConnectTime method, of class BasicConnection.
*/ */
@Test @Test
public void testGetConnectTime() throws Exception { public void testGetConnectTime() throws Exception {
System.out.println("getConnectTime"); System.out.println("getConnectTime");
ServerSocket server = openServerSocket(); try (PortManager.PortRef portRef = PortManager.getInstance().reservePort())
try { {
TCProtocolAdaptor adapter = mock(TCProtocolAdaptor.class); try (ServerSocket server = openServerSocket(portRef.port())) {
BufferManagerFactory buffer = mock(BufferManagerFactory.class); TCProtocolAdaptor adapter = mock(TCProtocolAdaptor.class);
when(buffer.createBufferManager(any(SocketChannel.class), any(boolean.clas BufferManagerFactory buffer = mock(BufferManagerFactory.class);
s))).thenReturn(mock(BufferManager.class)); when(buffer.createBufferManager(any(SocketChannel.class), any(boolean.cl
Function<TCConnection, Socket> close = s->null; ass))).thenReturn(mock(BufferManager.class));
BasicConnection instance = new BasicConnection("", adapter, buffer, close) Function<TCConnection, Socket> close = s -> null;
; BasicConnection instance = new BasicConnection("", adapter, buffer, clos
long expResult = 0L; e);
assertEquals(expResult, instance.getConnectTime()); long expResult = 0L;
instance.connect(new TCSocketAddress(server.getLocalPort()), 0); assertEquals(expResult, instance.getConnectTime());
assertNotEquals(expResult, instance.getConnectTime()); instance.connect(new TCSocketAddress(server.getLocalPort()), 0);
instance.close(0); assertNotEquals(expResult, instance.getConnectTime());
} finally { instance.close(0);
server.close(); }
} }
} }
/** /**
* Test of getIdleTime method, of class BasicConnection. * Test of getIdleTime method, of class BasicConnection.
*/ */
@Test @Test
public void testGetIdleTime() throws Exception { public void testGetIdleTime() throws Exception {
System.out.println("getIdleTime"); System.out.println("getIdleTime");
ServerSocket server = openServerSocket(); try (PortManager.PortRef portRef = PortManager.getInstance().reservePort())
try { {
TCProtocolAdaptor adapter = mock(TCProtocolAdaptor.class); try (ServerSocket server = openServerSocket(portRef.port())) {
BufferManagerFactory buffer = mock(BufferManagerFactory.class); TCProtocolAdaptor adapter = mock(TCProtocolAdaptor.class);
BufferManager mgr = mock(BufferManager.class); BufferManagerFactory buffer = mock(BufferManagerFactory.class);
when(buffer.createBufferManager(any(SocketChannel.class), any(boolean.clas BufferManager mgr = mock(BufferManager.class);
s))).thenReturn(mgr); when(buffer.createBufferManager(any(SocketChannel.class), any(boolean.cl
Function<TCConnection, Socket> close = s->null; ass))).thenReturn(mgr);
BasicConnection instance = new BasicConnection("", adapter, buffer, close) Function<TCConnection, Socket> close = s -> null;
; BasicConnection instance = new BasicConnection("", adapter, buffer, clos
instance.connect(new TCSocketAddress(server.getLocalPort()), 0); e);
long idleTime = instance.getIdleTime(); instance.connect(new TCSocketAddress(server.getLocalPort()), 0);
Thread.sleep(1000); long idleTime = instance.getIdleTime();
assertNotEquals(idleTime, instance.getIdleTime()); Thread.sleep(1000);
idleTime = instance.getIdleTime(); assertNotEquals(idleTime, instance.getIdleTime());
WireProtocolMessage msg = mock(WireProtocolMessage.class); idleTime = instance.getIdleTime();
when(msg.getHeader()).thenReturn(mock(WireProtocolHeader.class)); WireProtocolMessage msg = mock(WireProtocolMessage.class);
when(msg.getEntireMessageData()).thenReturn(new TCByteBuffer[] {mock(TCByt when(msg.getHeader()).thenReturn(mock(WireProtocolHeader.class));
eBuffer.class)}); when(msg.getEntireMessageData()).thenReturn(new TCByteBuffer[] { mock(TC
instance.putMessage(msg); ByteBuffer.class) });
assertTrue(idleTime>instance.getIdleTime()); instance.putMessage(msg);
instance.close(0); assertTrue(idleTime > instance.getIdleTime());
} catch (Exception e) { instance.close(0);
e.printStackTrace(); } catch (Exception e) {
} finally { e.printStackTrace();
server.close(); }
} }
} }
/** /**
* Test of getIdleReceiveTime method, of class BasicConnection. * Test of getIdleReceiveTime method, of class BasicConnection.
*/ */
@Test @Test
public void testGetIdleReceiveTime() throws Exception { public void testGetIdleReceiveTime() throws Exception {
System.out.println("getIdleReceiveTime"); System.out.println("getIdleReceiveTime");
ServerSocket server = openServerSocket(); try (PortManager.PortRef portRef = PortManager.getInstance().reservePort())
try { {
TCProtocolAdaptor adapter = mock(TCProtocolAdaptor.class); try (ServerSocket server = openServerSocket(portRef.port())) {
BufferManagerFactory buffer = mock(BufferManagerFactory.class); TCProtocolAdaptor adapter = mock(TCProtocolAdaptor.class);
when(buffer.createBufferManager(any(SocketChannel.class), any(boolean.clas BufferManagerFactory buffer = mock(BufferManagerFactory.class);
s))).thenReturn(mock(BufferManager.class)); when(buffer.createBufferManager(any(SocketChannel.class), any(boolean.cl
Function<TCConnection, Socket> close = s->null; ass))).thenReturn(mock(BufferManager.class));
BasicConnection instance = new BasicConnection("", adapter, buffer, close) Function<TCConnection, Socket> close = s -> null;
; BasicConnection instance = new BasicConnection("", adapter, buffer, clos
instance.connect(new TCSocketAddress(server.getLocalPort()), 0); e);
long idleTime = instance.getIdleTime(); instance.connect(new TCSocketAddress(server.getLocalPort()), 0);
Thread.sleep(1000); long idleTime = instance.getIdleTime();
assertNotEquals(idleTime, instance.getIdleTime()); Thread.sleep(1000);
instance.close(0); assertNotEquals(idleTime, instance.getIdleTime());
} finally { instance.close(0);
server.close(); }
} }
} }
/** /**
* Test of addListener method, of class BasicConnection. * Test of addListener method, of class BasicConnection.
*/ */
@Test @Test
public void testListener() throws Exception { public void testListener() throws Exception {
System.out.println("addListener"); System.out.println("addListener");
ServerSocket server = openServerSocket(); try (PortManager.PortRef portRef = PortManager.getInstance().reservePort())
try { {
TCProtocolAdaptor adapter = mock(TCProtocolAdaptor.class); try (ServerSocket server = openServerSocket(portRef.port())) {
BufferManagerFactory buffer = mock(BufferManagerFactory.class); TCProtocolAdaptor adapter = mock(TCProtocolAdaptor.class);
when(buffer.createBufferManager(any(SocketChannel.class), any(boolean.clas BufferManagerFactory buffer = mock(BufferManagerFactory.class);
s))).thenReturn(mock(BufferManager.class)); when(buffer.createBufferManager(any(SocketChannel.class), any(boolean.cl
Function<TCConnection, Socket> close = s->null; ass))).thenReturn(mock(BufferManager.class));
BasicConnection instance = new BasicConnection("", adapter, buffer, close) Function<TCConnection, Socket> close = s -> null;
; BasicConnection instance = new BasicConnection("", adapter, buffer, clos
TCConnectionEventListener listener = mock(TCConnectionEventListener.class) e);
; TCConnectionEventListener listener = mock(TCConnectionEventListener.clas
instance.addListener(listener); s);
instance.connect(new TCSocketAddress(server.getLocalPort()), 0); instance.addListener(listener);
instance.close(0); instance.connect(new TCSocketAddress(server.getLocalPort()), 0);
verify(listener).closeEvent(any(TCConnectionEvent.class)); instance.close(0);
verify(listener).connectEvent(any(TCConnectionEvent.class)); verify(listener).closeEvent(any(TCConnectionEvent.class));
} finally { verify(listener).connectEvent(any(TCConnectionEvent.class));
server.close(); }
} }
} }
} }
 End of changes. 10 change blocks. 
82 lines changed or deleted 80 lines changed or added

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