HCOLL-134 ( release draft cut of the code so that I can test it across my network )

This commit is contained in:
Rob Austin
2014-10-01 16:26:02 +01:00
parent 1cc2a7f27b
commit ab4c51b852
9 changed files with 655 additions and 330 deletions
@@ -26,16 +26,8 @@ package net.openhft.chronicle.map;
import junit.framework.TestSuite;*/
import net.openhft.chronicle.map.jrs166.JSR166TestCase;
import org.junit.Test;
import java.io.File;
import java.io.IOException;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
import java.util.function.BiFunction;
import static org.junit.Assert.*;
public class ConcurrentMap8Test extends JSR166TestCase {
@@ -43,7 +35,9 @@ public class ConcurrentMap8Test extends JSR166TestCase {
private static final double EPSILON = 1E-5;
static ConcurrentMap<Long, Long> longMap;
private static ConcurrentMap<Long, Long> newLongMap() {
// ******** commented out for the moment as it only works in java8 ********************************
/* private static ConcurrentMap<Long, Long> newLongMap() {
//First create (or access if already created) the shared map
final ChronicleMapBuilder<Long, Long> builder = ChronicleMapBuilder.of(Long.class, Long.class);
@@ -87,9 +81,9 @@ public class ConcurrentMap8Test extends JSR166TestCase {
}
/**
*//**
* Returns a new map from Integers 1-5 to Strings "A"-"E".
*/
*//*
private static ConcurrentMap map5() {
ConcurrentMap map = newIntegerStringMap();
assertTrue(map.isEmpty());
@@ -105,9 +99,9 @@ public class ConcurrentMap8Test extends JSR166TestCase {
return map;
}
/**
*//**
* Returns a new map from Integers 1-5 to Strings "A"-"E".
*/
*//*
private static ConcurrentHashMap map5ConcurrentHashMap() {
ConcurrentHashMap<Integer, String> map = new ConcurrentHashMap<Integer, String>(5);
assertTrue(map.isEmpty());
@@ -153,9 +147,9 @@ public class ConcurrentMap8Test extends JSR166TestCase {
return longMap;
}
/**
*//**
* getOrDefault returns value if present, else default
*/
*//*
@Test
public void testGetOrDefault() {
ConcurrentMap map = map5();
@@ -163,9 +157,9 @@ public class ConcurrentMap8Test extends JSR166TestCase {
assertEquals(map.getOrDefault(six, "Z"), "Z");
}
/**
*//**
* computeIfAbsent adds when the given key is not present
*/
*//*
@Test
public void testComputeIfAbsent() {
ConcurrentMap map = map5();
@@ -173,18 +167,18 @@ public class ConcurrentMap8Test extends JSR166TestCase {
assertTrue(map.containsKey(six));
}
/**
*//**
* computeIfAbsent does not replace if the key is already present
*/
*//*
@Test
public void testComputeIfAbsent2() {
ConcurrentMap map = map5();
assertEquals("A", map.computeIfAbsent(one, (x) -> "Z"));
}
/**
*//**
* computeIfAbsent does not add if function returns null
*/
*//*
@Test
public void testComputeIfAbsent3() {
ConcurrentMap map = map5();
@@ -192,9 +186,9 @@ public class ConcurrentMap8Test extends JSR166TestCase {
assertFalse(map.containsKey(six));
}
/**
*//**
* computeIfPresent does not replace if the key is already present
*/
*//*
@Test
public void testComputeIfPresent() {
ConcurrentMap map = map5();
@@ -202,18 +196,18 @@ public class ConcurrentMap8Test extends JSR166TestCase {
assertFalse(map.containsKey(six));
}
/**
*//**
* computeIfPresent adds when the given key is not present
*/
*//*
@Test
public void testComputeIfPresent2() {
ConcurrentMap map = map5();
assertEquals("Z", map.computeIfPresent(one, (x, y) -> "Z"));
}
/**
*//**
* compute does not replace if the function returns null
*/
*//*
@Test
public void testCompute() {
ConcurrentMap map = map5();
@@ -221,27 +215,27 @@ public class ConcurrentMap8Test extends JSR166TestCase {
assertFalse(map.containsKey(six));
}
/**
*//**
* compute adds when the given key is not present
*/
*//*
@Test
public void testCompute2() {
ConcurrentMap map = map5();
assertEquals("Z", map.compute(six, (x, y) -> "Z"));
}
/**
*//**
* compute replaces when the given key is present
*/
*//*
@Test
public void testCompute3() {
ConcurrentMap map = map5();
assertEquals("Z", map.compute(one, (x, y) -> "Z"));
}
/**
*//**
* compute removes when the given key is present and function returns null
*/
*//*
@Test
public void testCompute4() {
ConcurrentMap map = map5();
@@ -252,27 +246,27 @@ public class ConcurrentMap8Test extends JSR166TestCase {
assertFalse(map.containsKey(one));
}
/**
*//**
* merge adds when the given key is not present
*/
*//*
@Test
public void testMerge1() {
ConcurrentMap map = map5();
assertEquals("Y", map.merge(six, "Y", (x, y) -> "Z"));
}
/**
*//**
* merge replaces when the given key is present
*/
*//*
@Test
public void testMerge2() {
ConcurrentMap map = map5();
assertEquals("Z", map.merge(one, "Y", (x, y) -> "Z"));
}
/**
*//**
* merge removes when the given key is present and function returns null
*/
*//*
@Test
public void testMerge3() {
ConcurrentMap map = map5();
@@ -280,9 +274,9 @@ public class ConcurrentMap8Test extends JSR166TestCase {
assertFalse(map.containsKey(one));
}
/*
*//*
* replaceAll replaces all matching values.
*/
*//*
@Test
public void testReplaceAll() {
ConcurrentMap<Integer, String> map = map5();
@@ -299,18 +293,18 @@ public class ConcurrentMap8Test extends JSR166TestCase {
assertEquals("Z", map.get(five));
}
/**
*//**
* Default-constructed set is empty
*/
*//*
@Test
public void testNewKeySet() {
Set a = ConcurrentHashMap.newKeySet();
assertTrue(a.isEmpty());
}
/**
*//**
* keySet.addAll adds each element from the given collection
*/
*//*
@Test
public void testAddAll() {
Set full = populatedSet(3);
@@ -322,9 +316,9 @@ public class ConcurrentMap8Test extends JSR166TestCase {
assertEquals(6, full.size());
}
/**
*//**
* keySet.addAll adds each element from the given collection that did not already exist in the set
*/
*//*
@Test
public void testAddAll2() {
Set full = populatedSet(3);
@@ -336,9 +330,9 @@ public class ConcurrentMap8Test extends JSR166TestCase {
assertEquals(5, full.size());
}
/**
*//**
* keySet.add will not add the element if it already exists in the set
*/
*//*
@Test
public void testAdd2() {
Set full = populatedSet(3);
@@ -346,9 +340,9 @@ public class ConcurrentMap8Test extends JSR166TestCase {
assertEquals(3, full.size());
}
/**
*//**
* keySet.add adds the element when it does not exist in the set
*/
*//*
@Test
public void testAdd3() {
Set full = populatedSet(3);
@@ -356,9 +350,9 @@ public class ConcurrentMap8Test extends JSR166TestCase {
assertTrue(full.contains(three));
}
/**
*//**
* keySet.add throws UnsupportedOperationException if no default mapped value
*/
*//*
@Test
public void testAdd4() {
Set full = map5().keySet();
@@ -369,9 +363,9 @@ public class ConcurrentMap8Test extends JSR166TestCase {
}
}
/**
*//**
* keySet.add throws NullPointerException if the specified key is null
*/
*//*
@Test
public void testAdd5() {
Set full = populatedSet(3);
@@ -382,9 +376,9 @@ public class ConcurrentMap8Test extends JSR166TestCase {
}
}
/**
*//**
* keyset.clear removes all elements from the set
*/
*//*
@Test
public void testClear() {
Set full = populatedSet(3);
@@ -392,9 +386,9 @@ public class ConcurrentMap8Test extends JSR166TestCase {
assertEquals(0, full.size());
}
/**
*//**
* keyset.contains returns true for added elements
*/
*//*
@Test
public void testContains() {
Set full = populatedSet(3);
@@ -402,9 +396,9 @@ public class ConcurrentMap8Test extends JSR166TestCase {
assertFalse(full.contains(five));
}
/**
*//**
* KeySets with equal elements are equal
*/
*//*
@Test
public void testEquals() {
Set a = populatedSet(3);
@@ -421,9 +415,9 @@ public class ConcurrentMap8Test extends JSR166TestCase {
assertEquals(a.hashCode(), b.hashCode());
}
/**
*//**
* KeySet.containsAll returns true for collections with subset of elements
*/
*//*
@Test
public void testContainsAll() {
Set full = populatedSet(3);
@@ -435,9 +429,9 @@ public class ConcurrentMap8Test extends JSR166TestCase {
assertFalse(full.containsAll(v));
}
/**
*//**
* KeySet.isEmpty is true when empty, else false
*/
*//*
@Test
public void testIsEmpty() {
Set empty = ConcurrentHashMap.newKeySet();
@@ -446,9 +440,9 @@ public class ConcurrentMap8Test extends JSR166TestCase {
assertFalse(full.isEmpty());
}
/**
*//**
* KeySet.iterator() returns an iterator containing the elements of the set
*/
*//*
@Test
public void testIterator() {
Collection empty = ConcurrentHashMap.newKeySet();
@@ -479,9 +473,9 @@ public class ConcurrentMap8Test extends JSR166TestCase {
}
}
/**
*//**
* KeySet.iterator.remove removes current element
*/
*//*
@Test
public void testIteratorRemove() {
Set q = populatedSet(3);
@@ -495,9 +489,9 @@ public class ConcurrentMap8Test extends JSR166TestCase {
assertFalse(it.hasNext());
}
/**
*//**
* KeySet.toString holds toString of elements
*/
*//*
@Test
public void testToString() {
assertEquals("[]", ConcurrentHashMap.newKeySet().toString());
@@ -507,9 +501,9 @@ public class ConcurrentMap8Test extends JSR166TestCase {
assertTrue(s.contains(String.valueOf(i)));
}
/**
*//**
* KeySet.removeAll removes all elements from the given collection
*/
*//*
@Test
public void testRemoveAll() {
Set full = populatedSet(3);
@@ -520,9 +514,9 @@ public class ConcurrentMap8Test extends JSR166TestCase {
assertEquals(1, full.size());
}
/**
*//**
* KeySet.remove removes an element
*/
*//*
@Test
public void testRemove() {
Set full = populatedSet(3);
@@ -531,9 +525,9 @@ public class ConcurrentMap8Test extends JSR166TestCase {
assertEquals(2, full.size());
}
/**
*//**
* keySet.size returns the number of elements
*/
*//*
@Test
public void testSize() {
Set empty = ConcurrentHashMap.newKeySet();
@@ -542,9 +536,9 @@ public class ConcurrentMap8Test extends JSR166TestCase {
assertEquals(0, empty.size());
}
/**
*//**
* KeySet.toArray() returns an Object array containing all elements from the set
*/
*//*
@Test
public void testToArray() {
Object[] a = ConcurrentHashMap.newKeySet().toArray();
@@ -562,9 +556,9 @@ public class ConcurrentMap8Test extends JSR166TestCase {
assertSame(Object[].class, full.toArray().getClass());
}
/**
*//**
* toArray(Integer array) returns an Integer array containing all elements from the set
*/
*//*
@Test
public void testToArray2() {
Collection empty = ConcurrentHashMap.newKeySet();
@@ -599,9 +593,9 @@ public class ConcurrentMap8Test extends JSR166TestCase {
assertTrue(Arrays.asList(elements).containsAll(Arrays.asList(full.toArray(a))));
}
/**
*//**
* A deserialized serialized set is equal
*/
*//*
@Test
public void testSerialization() throws Exception {
int size = 20;
@@ -623,5 +617,5 @@ public class ConcurrentMap8Test extends JSR166TestCase {
}
}
*/
}
@@ -1,6 +1,10 @@
package net.openhft.chronicle.map;
import junit.framework.TestCase;
import org.junit.Ignore;
import org.junit.Test;
import java.io.IOException;
public class NodeDiscoveryBroadcasterTest extends TestCase {
@@ -8,93 +12,25 @@ public class NodeDiscoveryBroadcasterTest extends TestCase {
// test to stop it erroring with no test
}
/* @Test
@Ignore
public void test() throws IOException, InterruptedException {
final UdpReplicationConfig udpConfig = UdpReplicationConfig
.simple(Inet4Address.getByName("255.255.255.255"), 1235);
final Bytes identifierBitSetBits = new ByteBufferBytes(ByteBuffer.allocate(128 / 8));
final RemoteNodes remoteNodes = new RemoteNodes(identifierBitSetBits);
UDPEventListener udpEventListener = new UDPEventListener() {
@Override
public void onRemoteNodeEvent(RemoteNodes allNodes, byte remoteProposedId) {
}
};
BytesExternalizableImpl externalizable = new BytesExternalizableImpl(remoteNodes, udpEventListener);
private ChronicleMap<Integer, CharSequence> map1;
private ChronicleMap<Integer, CharSequence> map2;
private volatile byte proposedIdentifier = 1;
private volatile boolean useAnotherIdentifer = false;
final NodeDiscoveryBroadcaster nodeDiscoveryBroadcaster
= new NodeDiscoveryBroadcaster(udpConfig, 1024, externalizable);
externalizable.setModificationNotifier(nodeDiscoveryBroadcaster);
Thread.sleep(1000);
externalizable.sendBootStrap();
externalizable.add(new InetSocketAddress("myhost", 8888));
externalizable.add(new InetSocketAddress("myOtherHost", 8888));
externalizable.add((byte) 2);
externalizable.onChange();
Thread.sleep(10000);
externalizable.add((byte) 2);
externalizable.onChange();
Thread.sleep(10000);
externalizable.add((byte) 3);
externalizable.onChange();
Thread.sleep(10000);
externalizable.add((byte) 4);
externalizable.onChange();
Thread.sleep(10000);
externalizable.add((byte) 1);
externalizable.onChange();
Thread.sleep(10000);
externalizable.onChange();
Thread.sleep(1000);
}
@Test
@Ignore
public void testJustListen() throws IOException, InterruptedException {
public void test2() throws IOException, InterruptedException {
final UdpReplicationConfig udpConfig = UdpReplicationConfig
.simple(Inet4Address.getByName("255.255.255.255"), 1235);
DiscoveryCluster discoveryCluster = new DiscoveryCluster();
final Bytes identifierBitSetBits = new ByteBufferBytes(ByteBuffer.allocate(128 / 8));
final RemoteNodes remoteNodes = new RemoteNodes(identifierBitSetBits);
UDPEventListener udpEventListener = new UDPEventListener() {
@Override
public void onRemoteNodeEvent(RemoteNodes allNodes, byte remoteProposedId) {
}
};
BytesExternalizableImpl externalizable = new BytesExternalizableImpl(remoteNodes, udpEventListener);
ChronicleMap<Integer, CharSequence> map = discoveryCluster.discoverMap(1025, 8086);
}
final NodeDiscoveryBroadcaster nodeDiscoveryBroadcaster
= new NodeDiscoveryBroadcaster(udpConfig, 1024, externalizable);
externalizable.setModificationNotifier(nodeDiscoveryBroadcaster);
Thread.sleep(10000000);
}*/
}