"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "dso-l2/src/test/java/com/tc/net/groups/TCGroupManagerImplTest.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.

TCGroupManagerImplTest.java  (terracotta-core-5.7.0):TCGroupManagerImplTest.java  (terracotta-core-5.7.1)
skipping to change at line 39 skipping to change at line 39
import com.tc.lang.ThrowableHandlerImpl; import com.tc.lang.ThrowableHandlerImpl;
import com.tc.net.NodeID; import com.tc.net.NodeID;
import com.tc.net.ServerID; import com.tc.net.ServerID;
import com.tc.net.protocol.tcm.ChannelEvent; import com.tc.net.protocol.tcm.ChannelEvent;
import com.tc.net.protocol.tcm.ChannelEventListener; import com.tc.net.protocol.tcm.ChannelEventListener;
import com.tc.net.protocol.tcm.MessageChannel; import com.tc.net.protocol.tcm.MessageChannel;
import com.tc.net.protocol.tcm.MessageMonitor; import com.tc.net.protocol.tcm.MessageMonitor;
import com.tc.net.protocol.tcm.TCMessageType; import com.tc.net.protocol.tcm.TCMessageType;
import com.tc.net.protocol.transport.NullConnectionPolicy; import com.tc.net.protocol.transport.NullConnectionPolicy;
import com.tc.object.session.SessionID; import com.tc.object.session.SessionID;
import com.tc.objectserver.impl.Topology;
import com.tc.objectserver.impl.TopologyManager; import com.tc.objectserver.impl.TopologyManager;
import com.tc.properties.TCPropertiesImpl; import com.tc.properties.TCPropertiesImpl;
import com.tc.test.TCTestCase; import com.tc.test.TCTestCase;
import com.tc.util.PortChooser;
import com.tc.util.State; import com.tc.util.State;
import com.tc.util.UUID; import com.tc.util.UUID;
import com.tc.util.concurrent.NoExceptionLinkedQueue; import com.tc.util.concurrent.NoExceptionLinkedQueue;
import com.tc.util.runtime.ThreadDump; import com.tc.util.runtime.ThreadDump;
import org.mockito.Mockito; import org.mockito.Mockito;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.terracotta.utilities.test.net.PortManager;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
import java.util.List;
import java.util.Set; import java.util.Set;
import java.util.concurrent.LinkedBlockingQueue; import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicReference; import java.util.concurrent.atomic.AtomicReference;
import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.spy; import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.when; import static org.mockito.Mockito.when;
import static org.powermock.api.mockito.PowerMockito.mock; import static org.powermock.api.mockito.PowerMockito.mock;
//TODO: Fix this test to use something other than concrete message types (that i ncidentally no longer exist) //TODO: Fix this test to use something other than concrete message types (that i ncidentally no longer exist)
public class TCGroupManagerImplTest extends TCTestCase { public class TCGroupManagerImplTest extends TCTestCase {
private final static String LOCALHOST = "localhost"; private final static String LOCALHOST = "localhost";
private int ports[]; private List<PortManager.PortRef> ports;
private int groupPorts[]; private List<PortManager.PortRef> groupPorts;
private TCGroupManagerImpl groups[]; private TCGroupManagerImpl groups[];
private TestGroupMessageListener listeners[]; private TestGroupMessageListener listeners[];
private TestGroupEventListener groupEventListeners[]; private TestGroupEventListener groupEventListeners[];
private Node nodes[]; private Node nodes[];
private AtomicReference<Throwable> error; private AtomicReference<Throwable> error;
private MockStageManagerFactory stages; private MockStageManagerFactory stages;
private void setupGroups(int n) throws Exception { private void setupGroups(int n) throws Exception {
ports = new int[n];
groupPorts = new int[n];
groups = new TCGroupManagerImpl[n]; groups = new TCGroupManagerImpl[n];
listeners = new TestGroupMessageListener[n]; listeners = new TestGroupMessageListener[n];
groupEventListeners = new TestGroupEventListener[n]; groupEventListeners = new TestGroupEventListener[n];
nodes = new Node[n]; nodes = new Node[n];
error = new AtomicReference<>(); error = new AtomicReference<>();
stages = new MockStageManagerFactory(LoggerFactory.getLogger(TCGroupManagerI mplTest.class), new ThreadGroup("stage-manager")); stages = new MockStageManagerFactory(LoggerFactory.getLogger(TCGroupManagerI mplTest.class), new ThreadGroup("stage-manager"));
PortChooser pc = new PortChooser(); PortManager portManager = PortManager.getInstance();
ports = portManager.reservePorts(n);
groupPorts = portManager.reservePorts(n);
for (int i = 0; i < n; ++i) { for (int i = 0; i < n; ++i) {
ports[i] = pc.chooseRandom2Port(); nodes[i] = new Node(LOCALHOST, ports.get(i).port(), groupPorts.get(i).port
groupPorts[i] = ports[i] + 1; ());
nodes[i] = new Node(LOCALHOST, ports[i], groupPorts[i]);
} }
for (int i = 0; i < n; ++i) { for (int i = 0; i < n; ++i) {
groups[i] = new TCGroupManagerImpl(new NullConnectionPolicy(), LOCALHOST, ports[i], groupPorts[i], groups[i] = new TCGroupManagerImpl(new NullConnectionPolicy(), LOCALHOST, ports.get(i).port(), groupPorts.get(i).port(),
stages.createStageManager(), RandomWeig htGenerator.createTestingFactory(2), stages.createStageManager(), RandomWeig htGenerator.createTestingFactory(2),
mock(TopologyManager.class)); mock(TopologyManager.class));
groups[i].setDiscover(new TCGroupMemberDiscoveryStatic(groups[i], nodes[i] )); groups[i].setDiscover(new TCGroupMemberDiscoveryStatic(groups[i], nodes[i] ));
groupEventListeners[i] = new TestGroupEventListener(groups[i]); groupEventListeners[i] = new TestGroupEventListener(groups[i]);
groups[i].registerForGroupEvents(groupEventListeners[i]); groups[i].registerForGroupEvents(groupEventListeners[i]);
System.out.println("Starting " + groups[i]); System.out.println("Starting " + groups[i]);
listeners[i] = new TestGroupMessageListener(2000); listeners[i] = new TestGroupMessageListener(2000);
} }
} }
private void tearGroups() throws Exception { private void tearGroups() throws Exception {
for (TCGroupManagerImpl group : groups) { try {
System.out.println("Shutting down " + group); for (TCGroupManagerImpl group : groups) {
group.shutdown(); System.out.println("Shutting down " + group);
group.shutdown();
}
stages.shutdown();
} finally {
if (ports != null) {
ports.forEach(PortManager.PortRef::close);
}
if (groupPorts != null) {
groupPorts.forEach(PortManager.PortRef::close);
}
} }
stages.shutdown();
throwExceptionIfNecessary(); throwExceptionIfNecessary();
} }
private void throwExceptionIfNecessary() { private void throwExceptionIfNecessary() {
Throwable t = error.get(); Throwable t = error.get();
if (t != null) { if (t != null) {
// Delete this block when ENG-418 is fixed // Delete this block when ENG-418 is fixed
if (t instanceof AssertionError && t.getCause() instanceof InterruptedExce ption) { if (t instanceof AssertionError && t.getCause() instanceof InterruptedExce ption) {
System.out.println("Ignoring exception until ENG-418 is fixed: "); System.out.println("Ignoring exception until ENG-418 is fixed: ");
t.printStackTrace(); t.printStackTrace();
skipping to change at line 146 skipping to change at line 153
Set<Node> nodeSet = new HashSet<>(); Set<Node> nodeSet = new HashSet<>();
Collections.addAll(nodeSet, nodes); Collections.addAll(nodeSet, nodes);
GroupConfiguration groupConfiguration1 = getGroupConfiguration(nodeSet, node s[0]); GroupConfiguration groupConfiguration1 = getGroupConfiguration(nodeSet, node s[0]);
GroupConfiguration groupConfiguration2 = getGroupConfiguration(nodeSet, node s[1]); GroupConfiguration groupConfiguration2 = getGroupConfiguration(nodeSet, node s[1]);
groups[0].join(groupConfiguration1); groups[0].join(groupConfiguration1);
groups[1].join(groupConfiguration2); groups[1].join(groupConfiguration2);
// open test // open test
groups[0].openChannel(LOCALHOST, groupPorts[1], new NullChannelEventListener ()); groups[0].openChannel(LOCALHOST, groupPorts.get(1).port(), new NullChannelEv entListener());
Thread.sleep(2000); Thread.sleep(2000);
assertEquals(1, groups[0].size()); assertEquals(1, groups[0].size());
assertEquals(1, groups[1].size()); assertEquals(1, groups[1].size());
TCGroupMember member1 = getMember(groups[0], 0); TCGroupMember member1 = getMember(groups[0], 0);
TCGroupMember member2 = getMember(groups[1], 0); TCGroupMember member2 = getMember(groups[1], 0);
assertTrue("Expected " + member1.getLocalNodeID() + " but got " + member2.g etPeerNodeID(), member1 assertTrue("Expected " + member1.getLocalNodeID() + " but got " + member2.g etPeerNodeID(), member1
.getLocalNodeID().equals(member2.getPeerNodeID())); .getLocalNodeID().equals(member2.getPeerNodeID()));
assertTrue("Expected " + member1.getPeerNodeID() + " but got " + member2.ge tLocalNodeID(), member1.getPeerNodeID() assertTrue("Expected " + member1.getPeerNodeID() + " but got " + member2.ge tLocalNodeID(), member1.getPeerNodeID()
skipping to change at line 238 skipping to change at line 245
Set<Node> nodeSet = new HashSet<>(); Set<Node> nodeSet = new HashSet<>();
Collections.addAll(nodeSet, nodes); Collections.addAll(nodeSet, nodes);
GroupConfiguration groupConfiguration1 = getGroupConfiguration(nodeSet, node s[0]); GroupConfiguration groupConfiguration1 = getGroupConfiguration(nodeSet, node s[0]);
GroupConfiguration groupConfiguration2 = getGroupConfiguration(nodeSet, node s[1]); GroupConfiguration groupConfiguration2 = getGroupConfiguration(nodeSet, node s[1]);
groups[0].join(groupConfiguration1); groups[0].join(groupConfiguration1);
groups[1].join(groupConfiguration2); groups[1].join(groupConfiguration2);
groups[0].openChannel(LOCALHOST, groupPorts[1], new NullChannelEventListener groups[0].openChannel(LOCALHOST, groupPorts.get(1).port(), new NullChannelEv
()); entListener());
groups[1].openChannel(LOCALHOST, groupPorts[0], new NullChannelEventListener groups[1].openChannel(LOCALHOST, groupPorts.get(0).port(), new NullChannelEv
()); entListener());
// wait one channel to be closed. // wait one channel to be closed.
Thread.sleep(2000); Thread.sleep(2000);
assertEquals(1, groups[0].size()); assertEquals(1, groups[0].size());
assertEquals(1, groups[1].size()); assertEquals(1, groups[1].size());
TCGroupMember m0 = getMember(groups[0], 0); TCGroupMember m0 = getMember(groups[0], 0);
TCGroupMember m1 = getMember(groups[1], 0); TCGroupMember m1 = getMember(groups[1], 0);
assertTrue("Expected " + m0.getLocalNodeID() + " but got " + m1.getPeerNode ID(), assertTrue("Expected " + m0.getLocalNodeID() + " but got " + m1.getPeerNode ID(),
m0.getLocalNodeID().equals(m1.getPeerNodeID())); m0.getLocalNodeID().equals(m1.getPeerNodeID()));
 End of changes. 13 change blocks. 
20 lines changed or deleted 28 lines changed or added

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