mirror of
https://github.com/OpenHFT/Chronicle-Map.git
synced 2021-09-13 01:26:12 +00:00
HCOLL-134 more work on node discovery
This commit is contained in:
@@ -21,6 +21,8 @@ import net.openhft.chronicle.hash.ChronicleHashInstanceConfig;
|
||||
import net.openhft.chronicle.hash.FindByName;
|
||||
import net.openhft.chronicle.hash.replication.ReplicationChannel;
|
||||
import net.openhft.chronicle.hash.replication.ReplicationHub;
|
||||
import net.openhft.lang.io.Bytes;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
@@ -62,9 +64,19 @@ class ReplicationHubFindByName implements FindByName {
|
||||
this.replicationHub = replicationHub;
|
||||
ReplicationChannel channel = replicationHub.createChannel((short) MAP_BY_NAME_CHANNEL);
|
||||
|
||||
|
||||
MapEventListener listener = new MapEventListener() {
|
||||
|
||||
@Override
|
||||
public void onPut(ChronicleMap map, Bytes entry, int metaDataBytes, boolean added, Object key, Object value, @Nullable Object replacedValue) {
|
||||
LOG.info("key=" + key);
|
||||
}
|
||||
};
|
||||
|
||||
this.map = (Map) of(CharSequence.class, ChronicleMapBuilderWithChannelId.class)
|
||||
.entrySize(2500)
|
||||
.entries(128)
|
||||
.eventListener(listener)
|
||||
.instance()
|
||||
.replicatedViaChannel(channel)
|
||||
.create();
|
||||
@@ -96,7 +108,7 @@ class ReplicationHubFindByName implements FindByName {
|
||||
TimeoutException,
|
||||
InterruptedException {
|
||||
|
||||
ChronicleMapBuilderWithChannelId chronicleMapBuilder = waitTillEntryReceived(1000, name);
|
||||
ChronicleMapBuilderWithChannelId chronicleMapBuilder = waitTillEntryReceived(5000, name);
|
||||
if (chronicleMapBuilder == null)
|
||||
throw new IllegalArgumentException("A map name=" + name + " can not be found.");
|
||||
|
||||
|
||||
@@ -54,7 +54,7 @@ public class MapByNameTest {
|
||||
.replication((byte) 1, TcpTransportAndNetworkConfig.of(8244))
|
||||
.removeReturnsNull(true);
|
||||
|
||||
// findMapByName.add(builder);
|
||||
// findMapByName.add(builder);
|
||||
}
|
||||
|
||||
final ChronicleMap<CharSequence, CharSequence> map = findMapByName.from("map1");
|
||||
@@ -63,10 +63,10 @@ public class MapByNameTest {
|
||||
Assert.assertEquals(map.get("hello"), "world");
|
||||
}
|
||||
|
||||
// @Test(expected = IllegalArgumentException.class)
|
||||
// public void testSerializingBuilderUnknownMap() throws TimeoutException, InterruptedException {
|
||||
// findMapByName.get("hello");
|
||||
// }
|
||||
// @Test(expected = IllegalArgumentException.class)
|
||||
// public void testSerializingBuilderUnknownMap() throws TimeoutException, InterruptedException {
|
||||
// findMapByName.get("hello");
|
||||
// }
|
||||
|
||||
|
||||
// currently work in progress
|
||||
@@ -83,7 +83,7 @@ public class MapByNameTest {
|
||||
.removeReturnsNull(true);
|
||||
|
||||
ReplicationHubFindByName mapByName = nodeDiscovery.mapByName();
|
||||
// mapByName.add(builder);
|
||||
// mapByName.add(builder);
|
||||
|
||||
ChronicleMap<Object, Object> myMap2 = mapByName.from("myMap");
|
||||
|
||||
@@ -94,7 +94,7 @@ public class MapByNameTest {
|
||||
|
||||
|
||||
final ReplicationHubFindByName mapByName = nodeDiscovery.mapByName();
|
||||
|
||||
Thread.sleep(2000);
|
||||
|
||||
ChronicleMapBuilder<CharSequence, CharSequence> builder = ChronicleMapBuilder.of(CharSequence
|
||||
.class, CharSequence.class)
|
||||
@@ -102,17 +102,15 @@ public class MapByNameTest {
|
||||
.name("myMap4")
|
||||
.removeReturnsNull(true);
|
||||
|
||||
ChronicleMap<String, String> chronicleHash = mapByName.create(builder);
|
||||
chronicleHash.put("hello", "world");
|
||||
// ChronicleMap<String, String> map = mapByName.create(builder);
|
||||
// map.put("hello", "world");
|
||||
|
||||
final ChronicleMap<CharSequence, CharSequence> myMap = mapByName.from("myMap3");
|
||||
|
||||
// myMap.put("hello", "world");
|
||||
final ChronicleMap<CharSequence, CharSequence> map = mapByName.from("myMap4");
|
||||
|
||||
|
||||
System.out.print(myMap);
|
||||
|
||||
// allow time for replication
|
||||
Thread.sleep(2000);
|
||||
System.out.print(map);
|
||||
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user