diff --git a/io.janusproject.kernel/src/main/java/io/janusproject/kernel/services/hazelcast/HazelcastDistributedDataStructureService.java b/io.janusproject.kernel/src/main/java/io/janusproject/kernel/services/hazelcast/HazelcastDistributedDataStructureService.java index a5217cb..313cf1c 100644 --- a/io.janusproject.kernel/src/main/java/io/janusproject/kernel/services/hazelcast/HazelcastDistributedDataStructureService.java +++ b/io.janusproject.kernel/src/main/java/io/janusproject/kernel/services/hazelcast/HazelcastDistributedDataStructureService.java @@ -17,6 +17,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package io.janusproject.kernel.services.hazelcast; import java.util.Collection; @@ -133,6 +134,7 @@ public DMultiMap getMultiMap(String name, Comparator com private static final class MapView implements DMap { private final String name; + private final IMap map; MapView(String name, IMap map) { @@ -219,7 +221,7 @@ public V putIfAbsent(K key, V value) { @Override public void addDMapListener(DMapListener listener) { EntryListenerWrapper w = new EntryListenerWrapper<>(listener); - String k = this.map.addEntryListener(w, true); + String k = this.map.addEntryListener((MapListener) w, true); w.setHazelcastListener(k); } @@ -247,6 +249,7 @@ public void removeDMapListener(DMapListener listener) { private static final class MultiMapView implements DMultiMap { private final String name; + private final MultiMap map; MultiMapView(String name, MultiMap map) { @@ -468,6 +471,17 @@ public int add(K element, int occurrences) { throw new UnsupportedOperationException(); } + @Override + public boolean add(K element) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean remove(Object element) { + Collection values = MultiMapView.this.removeAll(element); + return values != null && !values.isEmpty(); + } + @Override public int remove(Object element, int occurrences) { if (occurrences < 0) { @@ -561,10 +575,12 @@ public Iterator iterator() { public boolean hasNext() { return entries.hasNext(); } + @Override public K next() { return entries.next().getKey(); } + @Override public void remove() { entries.remove(); @@ -584,24 +600,13 @@ public boolean containsAll(Collection elements) { } @Override - public boolean add(K element) { - throw new UnsupportedOperationException(); - } - - @Override - public boolean remove(Object element) { - Collection values = MultiMapView.this.removeAll(element); - return values != null && !values.isEmpty(); - } - - @Override - public boolean removeAll(Collection c) { - return MultiMapView.this.keySet().removeAll(c); + public boolean removeAll(Collection collection) { + return MultiMapView.this.keySet().removeAll(collection); } @Override - public boolean retainAll(Collection c) { - return MultiMapView.this.keySet().retainAll(c); + public boolean retainAll(Collection collection) { + return MultiMapView.this.keySet().retainAll(collection); } } diff --git a/io.janusproject.kernel/src/main/java/io/janusproject/kernel/services/hazelcast/HazelcastKernelDiscoveryService.java b/io.janusproject.kernel/src/main/java/io/janusproject/kernel/services/hazelcast/HazelcastKernelDiscoveryService.java index 3d08089..2dcafbb 100644 --- a/io.janusproject.kernel/src/main/java/io/janusproject/kernel/services/hazelcast/HazelcastKernelDiscoveryService.java +++ b/io.janusproject.kernel/src/main/java/io/janusproject/kernel/services/hazelcast/HazelcastKernelDiscoveryService.java @@ -226,7 +226,8 @@ protected synchronized void doStop() { * @mavengroupid $GroupId$ * @mavenartifactid $ArtifactId$ */ - private class HazelcastListener implements EntryListener, MembershipListener { + private class HazelcastListener implements MembershipListener, EntryAddedListener, + EntryRemovedListener, EntryEvictedListener { /** Construct. */ @@ -272,32 +273,11 @@ public void entryRemoved(EntryEvent event) { fireDisconnected(event); } - /** {@inheritDoc} - */ - @Override - public void entryUpdated(EntryEvent event) { - // - } - @Override public void entryEvicted(EntryEvent event) { fireDisconnected(event); } - /** {@inheritDoc} - */ - @Override - public void mapCleared(MapEvent event) { - throw new UnsupportedOperationException("this exception should never occur"); //$NON-NLS-1$ - } - - /** {@inheritDoc} - */ - @Override - public void mapEvicted(MapEvent event) { - throw new UnsupportedOperationException("this exception should never occur"); //$NON-NLS-1$ - } - private void fireDisconnected(EntryEvent event) { URI oldPeer = event.getValue(); assert (oldPeer != null); diff --git a/io.janusproject.kernel/src/test/java/io/janusproject/kernel/services/hazelcast/HazelcastDMapViewTest.java b/io.janusproject.kernel/src/test/java/io/janusproject/kernel/services/hazelcast/HazelcastDMapViewTest.java index a04fadf..19d775a 100644 --- a/io.janusproject.kernel/src/test/java/io/janusproject/kernel/services/hazelcast/HazelcastDMapViewTest.java +++ b/io.janusproject.kernel/src/test/java/io/janusproject/kernel/services/hazelcast/HazelcastDMapViewTest.java @@ -28,22 +28,14 @@ import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.verifyZeroInteractions; -import io.janusproject.services.distributeddata.DMapListener; -import io.janusproject.testutils.AbstractJanusTest; -import io.janusproject.testutils.IMapMock; -import io.janusproject.util.DataViewDelegate.Delegator; import java.util.Collection; -import java.util.Collections; import java.util.Map; -import java.util.Set; import java.util.Map.Entry; import java.util.UUID; import javax.annotation.Nullable; -import junit.framework.TestSuite; - import org.junit.After; import org.junit.Assume; import org.junit.Before; @@ -53,7 +45,6 @@ import org.junit.runners.Suite.SuiteClasses; import org.mockito.ArgumentCaptor; -import com.google.common.collect.Maps; import com.google.common.collect.testing.MapTestSuiteBuilder; import com.google.common.collect.testing.TestStringMapGenerator; import com.google.common.collect.testing.features.CollectionFeature; @@ -65,7 +56,10 @@ import com.hazelcast.core.IMap; import com.hazelcast.core.MultiMap; -import static org.junit.Assume.*; +import io.janusproject.services.distributeddata.DMapListener; +import io.janusproject.testutils.AbstractJanusTest; +import io.janusproject.testutils.HzMapMock; +import junit.framework.TestSuite; /** * @author $Author: sgalland$ @@ -174,7 +168,7 @@ public static TestSuite suite() { .using(new TestStringMapGenerator() { @Override protected Map create(Entry[] arg0) { - IMap map = new IMapMock<>(); + IMap map = new HzMapMock<>(); for(Entry entry : arg0) { map.put(entry.getKey(), entry.getValue()); } @@ -212,7 +206,7 @@ public static class ViewTests extends AbstractJanusTest { @Before public void setUp() { - this.map = new IMapMock<>(); + this.map = new HzMapMock<>(); this.view = new HazelcastDMapView<>(this.map); } @@ -244,7 +238,7 @@ public static class SpecificDMapFunctionTests extends AbstractJanusTest { @Before public void setUp() { - this.map = new IMapMock<>(); + this.map = new HzMapMock<>(); this.view = new HazelcastDMapView<>(this.map); } @@ -290,7 +284,7 @@ public static class ListeningFeatureTests extends AbstractJanusTest { @Before public void setUp() { this.listener = mock(DMapListener.class); - this.map = new IMapMock<>(); + this.map = new HzMapMock<>(); this.view = new HazelcastDMapView<>(this.map); } diff --git a/io.janusproject.kernel/src/test/java/io/janusproject/kernel/services/hazelcast/HazelcastDMultiMapViewTest.java b/io.janusproject.kernel/src/test/java/io/janusproject/kernel/services/hazelcast/HazelcastDMultiMapViewTest.java index b5988fc..8a0971d 100644 --- a/io.janusproject.kernel/src/test/java/io/janusproject/kernel/services/hazelcast/HazelcastDMultiMapViewTest.java +++ b/io.janusproject.kernel/src/test/java/io/janusproject/kernel/services/hazelcast/HazelcastDMultiMapViewTest.java @@ -29,10 +29,6 @@ import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.verifyZeroInteractions; -import io.janusproject.services.distributeddata.DMapListener; -import io.janusproject.testutils.AbstractJanusTest; -import io.janusproject.testutils.IMultiMapMock; -import io.janusproject.util.DataViewDelegate.Delegator; import java.util.Arrays; import java.util.Collection; @@ -67,6 +63,11 @@ import com.hazelcast.core.HazelcastInstance; import com.hazelcast.core.MultiMap; +import io.janusproject.services.distributeddata.DMapListener; +import io.janusproject.testutils.AbstractJanusTest; +import io.janusproject.testutils.HzMultiMapMock; +import io.janusproject.util.DataViewDelegate.Delegator; + /** * @author $Author: sgalland$ * @version $FullVersion$ @@ -196,7 +197,7 @@ public static class SimplifiedMultiMapOperationTests extends AbstractJanusTest { @Before public void setUp() { - this.map = new IMultiMapMock<>(UUID.randomUUID().toString()); + this.map = new HzMultiMapMock<>(UUID.randomUUID().toString()); this.map.put("a", "va1"); this.map.put("a", "va2"); this.map.put("b", "vb"); @@ -391,7 +392,7 @@ public static class ViewTests extends AbstractJanusTest { @Before public void setUp() { - this.map = new IMultiMapMock<>(UUID.randomUUID().toString()); + this.map = new HzMultiMapMock<>(UUID.randomUUID().toString()); this.view = new HazelcastDMultiMapView<>(this.map); } @@ -426,7 +427,7 @@ public static class SpecificDMultiMapFunctionTests extends AbstractJanusTest { @Before public void setUp() { - this.map = new IMultiMapMock<>(UUID.randomUUID().toString()); + this.map = new HzMultiMapMock<>(UUID.randomUUID().toString()); this.view = new HazelcastDMultiMapView<>(this.map); } @@ -505,7 +506,7 @@ public static class ListeningFeatureTests extends AbstractJanusTest { @Before public void setUp() { this.listener = mock(DMapListener.class); - this.map = new IMultiMapMock<>(UUID.randomUUID().toString()); + this.map = new HzMultiMapMock<>(UUID.randomUUID().toString()); this.view = new HazelcastDMultiMapView<>(this.map); } diff --git a/io.janusproject.kernel/src/test/java/io/janusproject/kernel/services/hazelcast/HazelcastKernelDiscoveryServiceTest.java b/io.janusproject.kernel/src/test/java/io/janusproject/kernel/services/hazelcast/HazelcastKernelDiscoveryServiceTest.java index dce1109..14d67a8 100644 --- a/io.janusproject.kernel/src/test/java/io/janusproject/kernel/services/hazelcast/HazelcastKernelDiscoveryServiceTest.java +++ b/io.janusproject.kernel/src/test/java/io/janusproject/kernel/services/hazelcast/HazelcastKernelDiscoveryServiceTest.java @@ -29,7 +29,7 @@ import io.janusproject.services.network.NetworkService; import io.janusproject.services.network.NetworkUtil; import io.janusproject.testutils.AbstractDependentServiceTest; -import io.janusproject.testutils.IMapMock; +import io.janusproject.testutils.HzMapMock; import io.janusproject.testutils.StartServiceForTest; import io.janusproject.util.TwoStepConstruction; @@ -110,7 +110,7 @@ public void setUp() throws Exception { this.hazelcastURI = NetworkUtil.toURI("tcp://123.124.125.126:5023"); //$NON-NLS-1$ this.kernelURI = NetworkUtil.toURI("tcp://123.124.125.126:34567"); //$NON-NLS-1$ this.contextId = UUID.randomUUID(); - this.kernels = new IMapMock<>(); + this.kernels = new HzMapMock<>(); this.hzInstance = Mockito.mock(HazelcastInstance.class); { Mockito.when(this.hzInstance.getMap(Matchers.anyString())).thenReturn(this.kernels); diff --git a/io.janusproject.kernel/src/test/java/io/janusproject/modules/hazelcast/AbstractSerializerTest.java b/io.janusproject.kernel/src/test/java/io/janusproject/modules/hazelcast/AbstractSerializerTest.java index d021bc9..24ff369 100644 --- a/io.janusproject.kernel/src/test/java/io/janusproject/modules/hazelcast/AbstractSerializerTest.java +++ b/io.janusproject.kernel/src/test/java/io/janusproject/modules/hazelcast/AbstractSerializerTest.java @@ -218,6 +218,20 @@ public void writeByteArray(byte[] arg0) throws IOException { public void writeData(Data arg0) throws IOException { throw new UnsupportedOperationException(); } + + /** {@inheritDoc} + */ + @Override + public void writeBooleanArray(boolean[] booleans) throws IOException { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} + */ + @Override + public void writeUTFArray(String[] values) throws IOException { + throw new UnsupportedOperationException(); + } } @@ -419,6 +433,20 @@ public byte[] readByteArray() throws IOException { public Data readData() throws IOException { throw new UnsupportedOperationException(); } + + /** {@inheritDoc} + */ + @Override + public boolean[] readBooleanArray() throws IOException { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} + */ + @Override + public String[] readUTFArray() throws IOException { + throw new UnsupportedOperationException(); + } } diff --git a/io.janusproject.kernel/src/test/java/io/janusproject/testutils/IMapMock.java b/io.janusproject.kernel/src/test/java/io/janusproject/testutils/HzMapMock.java similarity index 73% rename from io.janusproject.kernel/src/test/java/io/janusproject/testutils/IMapMock.java rename to io.janusproject.kernel/src/test/java/io/janusproject/testutils/HzMapMock.java index 797ec24..01a181d 100644 --- a/io.janusproject.kernel/src/test/java/io/janusproject/testutils/IMapMock.java +++ b/io.janusproject.kernel/src/test/java/io/janusproject/testutils/HzMapMock.java @@ -19,9 +19,6 @@ */ package io.janusproject.testutils; -import io.janusproject.services.distributeddata.DMap; -import io.janusproject.services.distributeddata.DMapListener; - import java.util.Collection; import java.util.HashMap; import java.util.Map; @@ -36,6 +33,8 @@ import com.hazelcast.core.IMap; import com.hazelcast.map.EntryProcessor; import com.hazelcast.map.MapInterceptor; +import com.hazelcast.map.listener.MapListener; +import com.hazelcast.map.listener.MapPartitionLostListener; import com.hazelcast.mapreduce.JobTracker; import com.hazelcast.mapreduce.aggregation.Aggregation; import com.hazelcast.mapreduce.aggregation.Supplier; @@ -52,7 +51,7 @@ * @param */ @SuppressWarnings("all") -public class IMapMock extends HashMap implements IMap { +public class HzMapMock extends HashMap implements IMap { private static final long serialVersionUID = -2482265223106773425L; @@ -60,7 +59,7 @@ public class IMapMock extends HashMap implements IMap { /** */ - public IMapMock() { + public HzMapMock() { // } @@ -71,13 +70,6 @@ public void destroy() { throw new UnsupportedOperationException(); } - /** {@inheritDoc} - */ - @Override - public Object getId() { - return this.name; - } - /** {@inheritDoc} */ @Override @@ -99,33 +91,33 @@ public String getServiceName() { throw new UnsupportedOperationException(); } - /** {@inheritDoc} - */ - @Override - public String addEntryListener(EntryListener arg0, boolean arg1) { - return UUID.randomUUID().toString(); - } - - /** {@inheritDoc} - */ - @Override - public String addEntryListener(EntryListener arg0, K arg1, boolean arg2) { - return UUID.randomUUID().toString(); - } - - /** {@inheritDoc} - */ - @Override - public String addEntryListener(EntryListener arg0, Predicate arg1, boolean arg2) { - return UUID.randomUUID().toString(); - } - - /** {@inheritDoc} - */ - @Override - public String addEntryListener(EntryListener arg0, Predicate arg1, K arg2, boolean arg3) { - return UUID.randomUUID().toString(); - } +// /** {@inheritDoc} +// */ +// @Override +// public String addEntryListener(EntryListener arg0, boolean arg1) { +// return UUID.randomUUID().toString(); +// } +// +// /** {@inheritDoc} +// */ +// @Override +// public String addEntryListener(EntryListener arg0, K arg1, boolean arg2) { +// return UUID.randomUUID().toString(); +// } +// +// /** {@inheritDoc} +// */ +// @Override +// public String addEntryListener(EntryListener arg0, Predicate arg1, boolean arg2) { +// return UUID.randomUUID().toString(); +// } +// +// /** {@inheritDoc} +// */ +// @Override +// public String addEntryListener(EntryListener arg0, Predicate arg1, K arg2, boolean arg3) { +// return UUID.randomUUID().toString(); +// } /** {@inheritDoc} */ @@ -141,29 +133,6 @@ public String addInterceptor(MapInterceptor arg0) { throw new UnsupportedOperationException(); } - /** {@inheritDoc} - */ - @Override - public String addLocalEntryListener(EntryListener arg0) { - throw new UnsupportedOperationException(); - } - - /** {@inheritDoc} - */ - @Override - public String addLocalEntryListener(EntryListener arg0, - Predicate arg1, boolean arg2) { - throw new UnsupportedOperationException(); - } - - /** {@inheritDoc} - */ - @Override - public String addLocalEntryListener(EntryListener arg0, - Predicate arg1, K arg2, boolean arg3) { - throw new UnsupportedOperationException(); - } - /** {@inheritDoc} */ @Override @@ -436,6 +405,14 @@ public boolean tryLock(K arg0) { throw new UnsupportedOperationException(); } + /** {@inheritDoc} + */ + @Override + public boolean tryLock(K key, long time, TimeUnit timeunit, long leaseTime, TimeUnit leaseTimeunit) + throws InterruptedException { + throw new UnsupportedOperationException(); + } + /** {@inheritDoc} */ @Override @@ -493,4 +470,117 @@ public void loadAll(Set arg0, boolean arg1) { throw new UnsupportedOperationException(); } + /** {@inheritDoc} + */ + @Override + public String addLocalEntryListener(MapListener listener) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} + */ + @Override + public String addLocalEntryListener(EntryListener listener) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} + */ + @Override + public String addLocalEntryListener(MapListener listener, Predicate predicate, boolean includeValue) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} + */ + @Override + public String addLocalEntryListener(EntryListener listener, Predicate predicate, boolean includeValue) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} + */ + @Override + public String addLocalEntryListener(MapListener listener, Predicate predicate, K key, boolean includeValue) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} + */ + @Override + public String addLocalEntryListener(EntryListener listener, Predicate predicate, K key, + boolean includeValue) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} + */ + @Override + public String addEntryListener(MapListener listener, boolean includeValue) { + return UUID.randomUUID().toString(); + } + + /** {@inheritDoc} + */ + @Override + public String addEntryListener(EntryListener listener, boolean includeValue) { + return UUID.randomUUID().toString(); + } + + /** {@inheritDoc} + */ + @Override + public String addPartitionLostListener(MapPartitionLostListener listener) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} + */ + @Override + public boolean removePartitionLostListener(String id) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} + */ + @Override + public String addEntryListener(MapListener listener, K key, boolean includeValue) { + return UUID.randomUUID().toString(); + } + + /** {@inheritDoc} + */ + @Override + public String addEntryListener(EntryListener listener, K key, boolean includeValue) { + return UUID.randomUUID().toString(); + } + + /** {@inheritDoc} + */ + @Override + public String addEntryListener(MapListener listener, Predicate predicate, boolean includeValue) { + return UUID.randomUUID().toString(); + } + + /** {@inheritDoc} + */ + @Override + public String addEntryListener(EntryListener listener, Predicate predicate, boolean includeValue) { + return UUID.randomUUID().toString(); + } + + /** {@inheritDoc} + */ + @Override + public String addEntryListener(MapListener listener, Predicate predicate, K key, boolean includeValue) { + return UUID.randomUUID().toString(); + } + + /** {@inheritDoc} + */ + @Override + public String addEntryListener(EntryListener listener, Predicate predicate, K key, boolean includeValue) { + return UUID.randomUUID().toString(); + } + } diff --git a/io.janusproject.kernel/src/test/java/io/janusproject/testutils/IMultiMapMock.java b/io.janusproject.kernel/src/test/java/io/janusproject/testutils/HzMultiMapMock.java similarity index 95% rename from io.janusproject.kernel/src/test/java/io/janusproject/testutils/IMultiMapMock.java rename to io.janusproject.kernel/src/test/java/io/janusproject/testutils/HzMultiMapMock.java index 873c1d3..66635f2 100644 --- a/io.janusproject.kernel/src/test/java/io/janusproject/testutils/IMultiMapMock.java +++ b/io.janusproject.kernel/src/test/java/io/janusproject/testutils/HzMultiMapMock.java @@ -51,7 +51,7 @@ * @param */ @SuppressWarnings("all") -public class IMultiMapMock implements MultiMap { +public class HzMultiMapMock implements MultiMap { private final String name; private final SetMultimap map; @@ -59,7 +59,7 @@ public class IMultiMapMock implements MultiMap { /** * @param name */ - public IMultiMapMock(String name) { + public HzMultiMapMock(String name) { this.name = name; Supplier> supplier = new Supplier>() { @Override @@ -87,11 +87,6 @@ public String toString() { return this.map.toString(); } - @Override - public Object getId() { - return getName(); - } - @Override public String getPartitionKey() { throw new UnsupportedOperationException(); @@ -228,6 +223,12 @@ public boolean tryLock(K key, long time, TimeUnit timeunit) throw new UnsupportedOperationException(); } + @Override + public boolean tryLock(K key, long time, TimeUnit timeunit, long leaseTime, TimeUnit leaseTimeunit) + throws InterruptedException { + throw new UnsupportedOperationException(); + } + @Override public void unlock(K key) { throw new UnsupportedOperationException(); diff --git a/pom.xml b/pom.xml index af47f12..e3ef173 100644 --- a/pom.xml +++ b/pom.xml @@ -45,7 +45,7 @@ 18.0 0.3.5 2.4 - 3.4.2 + 3.6-EA 12.0