From 073bf5032721ce5a6eca2bdcdf77a83e2ba922a9 Mon Sep 17 00:00:00 2001 From: Rob Austin Date: Tue, 18 Nov 2014 15:24:57 +0000 Subject: [PATCH] HCOLL-134 more work on node discovery --- .../map/ReplicationHubFindByName.java | 14 +++++++++- .../openhft/chronicle/map/MapByNameTest.java | 26 +++++++++---------- 2 files changed, 25 insertions(+), 15 deletions(-) diff --git a/src/main/java/net/openhft/chronicle/map/ReplicationHubFindByName.java b/src/main/java/net/openhft/chronicle/map/ReplicationHubFindByName.java index 6d2abcab2..24b4344c2 100644 --- a/src/main/java/net/openhft/chronicle/map/ReplicationHubFindByName.java +++ b/src/main/java/net/openhft/chronicle/map/ReplicationHubFindByName.java @@ -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."); diff --git a/src/test/java/net/openhft/chronicle/map/MapByNameTest.java b/src/test/java/net/openhft/chronicle/map/MapByNameTest.java index 763b4069c..07d11ab63 100644 --- a/src/test/java/net/openhft/chronicle/map/MapByNameTest.java +++ b/src/test/java/net/openhft/chronicle/map/MapByNameTest.java @@ -54,7 +54,7 @@ public class MapByNameTest { .replication((byte) 1, TcpTransportAndNetworkConfig.of(8244)) .removeReturnsNull(true); - // findMapByName.add(builder); + // findMapByName.add(builder); } final ChronicleMap 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 myMap2 = mapByName.from("myMap"); @@ -94,7 +94,7 @@ public class MapByNameTest { final ReplicationHubFindByName mapByName = nodeDiscovery.mapByName(); - + Thread.sleep(2000); ChronicleMapBuilder builder = ChronicleMapBuilder.of(CharSequence .class, CharSequence.class) @@ -102,17 +102,15 @@ public class MapByNameTest { .name("myMap4") .removeReturnsNull(true); - ChronicleMap chronicleHash = mapByName.create(builder); - chronicleHash.put("hello", "world"); + // ChronicleMap map = mapByName.create(builder); + // map.put("hello", "world"); - final ChronicleMap myMap = mapByName.from("myMap3"); - - // myMap.put("hello", "world"); + final ChronicleMap map = mapByName.from("myMap4"); - System.out.print(myMap); - + // allow time for replication Thread.sleep(2000); + System.out.print(map); }