Skip to content
This repository has been archived by the owner on Aug 23, 2023. It is now read-only.

Commit

Permalink
Upgrade to Hazelcast 3.6
Browse files Browse the repository at this point in the history
see #111

Signed-off-by: Stéphane Galland <galland@arakhne.org>
  • Loading branch information
gallandarakhneorg committed Nov 23, 2015
1 parent 15fe2ce commit 310dbcf
Show file tree
Hide file tree
Showing 9 changed files with 231 additions and 132 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -133,6 +134,7 @@ public <K, V> DMultiMap<K, V> getMultiMap(String name, Comparator<? super K> com
private static final class MapView<K, V> implements DMap<K, V> {

private final String name;

private final IMap<K, V> map;

MapView(String name, IMap<K, V> map) {
Expand Down Expand Up @@ -219,7 +221,7 @@ public V putIfAbsent(K key, V value) {
@Override
public void addDMapListener(DMapListener<? super K, ? super V> listener) {
EntryListenerWrapper<K, V> w = new EntryListenerWrapper<>(listener);
String k = this.map.addEntryListener(w, true);
String k = this.map.addEntryListener((MapListener) w, true);
w.setHazelcastListener(k);
}

Expand Down Expand Up @@ -247,6 +249,7 @@ public void removeDMapListener(DMapListener<? super K, ? super V> listener) {
private static final class MultiMapView<K, V> implements DMultiMap<K, V> {

private final String name;

private final MultiMap<K, V> map;

MultiMapView(String name, MultiMap<K, V> map) {
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -561,10 +575,12 @@ public Iterator<K> iterator() {
public boolean hasNext() {
return entries.hasNext();
}

@Override
public K next() {
return entries.next().getKey();
}

@Override
public void remove() {
entries.remove();
Expand All @@ -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);
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,8 @@ protected synchronized void doStop() {
* @mavengroupid $GroupId$
* @mavenartifactid $ArtifactId$
*/
private class HazelcastListener implements EntryListener<URI, URI>, MembershipListener {
private class HazelcastListener implements MembershipListener, EntryAddedListener<URI, URI>,
EntryRemovedListener<URI, URI>, EntryEvictedListener<URI, URI> {

/** Construct.
*/
Expand Down Expand Up @@ -272,32 +273,11 @@ public void entryRemoved(EntryEvent<URI, URI> event) {
fireDisconnected(event);
}

/** {@inheritDoc}
*/
@Override
public void entryUpdated(EntryEvent<URI, URI> event) {
//
}

@Override
public void entryEvicted(EntryEvent<URI, URI> 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<URI, URI> event) {
URI oldPeer = event.getValue();
assert (oldPeer != null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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$
Expand Down Expand Up @@ -174,7 +168,7 @@ public static TestSuite suite() {
.using(new TestStringMapGenerator() {
@Override
protected Map<String, String> create(Entry<String, String>[] arg0) {
IMap<String, String> map = new IMapMock<>();
IMap<String, String> map = new HzMapMock<>();
for(Entry<String, String> entry : arg0) {
map.put(entry.getKey(), entry.getValue());
}
Expand Down Expand Up @@ -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);
}

Expand Down Expand Up @@ -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);
}

Expand Down Expand Up @@ -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);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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$
Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -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);
}

Expand Down Expand Up @@ -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);
}

Expand Down Expand Up @@ -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);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

}

Expand Down Expand Up @@ -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();
}

}

Expand Down
Loading

0 comments on commit 310dbcf

Please sign in to comment.