Skip to content

Commit

Permalink
Fixes #566.
Browse files Browse the repository at this point in the history
  • Loading branch information
mdogan committed Jul 17, 2013
1 parent 98b249a commit 5da3975
Show file tree
Hide file tree
Showing 16 changed files with 116 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package com.hazelcast.client;

import com.hazelcast.core.ILock;
import com.hazelcast.core.Prefix;
import com.hazelcast.impl.ClusterOperation;
import com.hazelcast.impl.FactoryImpl;
import com.hazelcast.monitor.LocalLockStats;
Expand All @@ -27,11 +28,13 @@
import static com.hazelcast.client.ProxyHelper.check;

public class LockClientProxy implements ILock {
private static final String LOCK = Prefix.LOCK;

final ProxyHelper proxyHelper;
final Object lockObject;

public LockClientProxy(Object object, HazelcastClient client) {
proxyHelper = new ProxyHelper("", client);
proxyHelper = new ProxyHelper(LOCK, client);
lockObject = object;
check(lockObject);
}
Expand Down Expand Up @@ -81,19 +84,19 @@ private Object doLock(long timeout, TimeUnit timeUnit) {
}

public Condition newCondition() {
return null;
throw new UnsupportedOperationException();
}

public InstanceType getInstanceType() {
return InstanceType.LOCK;
}

public void destroy() {
proxyHelper.destroy();
proxyHelper.doOp(ClusterOperation.DESTROY, lockObject, null);
}

public Object getId() {
return new FactoryImpl.ProxyKey("lock", lockObject);
return new FactoryImpl.ProxyKey(LOCK, lockObject);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public class SemaphoreClientProxy implements ISemaphore {

public SemaphoreClientProxy(HazelcastClient hazelcastClient, String name) {
this.name = name;
proxyHelper = new ProxyHelper(getName(), hazelcastClient);
proxyHelper = new ProxyHelper(name, hazelcastClient);
}

public void acquire() throws InstanceDestroyedException, InterruptedException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,14 @@ public void after() throws Exception {
Hazelcast.shutdownAll();
}

@Test
public void testDestroy() {
HazelcastInstance h1 = Hazelcast.newHazelcastInstance(new Config());
HazelcastClient client = newHazelcastClient(h1);
AtomicNumber number = client.getAtomicNumber("testDestroy");
number.destroy();
}

@Test
public void testAtomicLong() {
HazelcastInstance h1 = Hazelcast.newHazelcastInstance(new Config());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package com.hazelcast.client;

import com.hazelcast.config.Config;
import com.hazelcast.core.*;
import com.hazelcast.impl.MemberImpl;
import com.hazelcast.nio.Address;
Expand Down Expand Up @@ -50,6 +51,14 @@ public void tearDown() throws Exception {
Hazelcast.shutdownAll();
}

@Test
public void testDestroy() {
HazelcastInstance h1 = Hazelcast.newHazelcastInstance(new Config());
HazelcastClient client = newHazelcastClient(h1);
ICountDownLatch latch = client.getCountDownLatch("testDestroy");
latch.destroy();
}

@Test
public void testClientCountDownLatchSimple() throws InterruptedException, IOException {
HazelcastInstance instance = Hazelcast.newHazelcastInstance(null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,10 @@

package com.hazelcast.client;

import com.hazelcast.core.HazelcastInstance;
import com.hazelcast.core.IList;
import com.hazelcast.core.ItemEvent;
import com.hazelcast.core.ItemListener;
import com.hazelcast.core.*;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;

import java.util.*;
import java.util.concurrent.CountDownLatch;
Expand All @@ -31,6 +29,7 @@
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;

@RunWith(com.hazelcast.util.RandomBlockJUnit4ClassRunner.class)
public class HazelcastClientListTest extends HazelcastClientTestBase {

@Test(expected = NullPointerException.class)
Expand All @@ -47,6 +46,13 @@ public void getListName() {
assertEquals("getListName", list.getName());
}

@Test
public void testDestroy() {
HazelcastClient hClient = getHazelcastClient();
IList<?> list = hClient.getList("testDestroy");
list.destroy();
}

@Test
@Ignore
public void addRemoveItemListener() throws InterruptedException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,15 @@
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.runner.RunWith;

import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;

import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;

@RunWith(com.hazelcast.util.RandomBlockJUnit4ClassRunner.class)
public class HazelcastClientLockTest extends HazelcastClientTestBase {

@BeforeClass
Expand All @@ -42,6 +44,13 @@ public void testLockNull() {
lock.lock();
}

@Test
public void testDestroy() {
HazelcastClient hClient = getHazelcastClient();
ILock lock = hClient.getLock("testDestroy");
lock.destroy();
}

@Test
public void testLockUnlock() throws InterruptedException {
HazelcastClient hClient = getHazelcastClient();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import com.hazelcast.util.Clock;
import org.junit.AfterClass;
import org.junit.Test;
import org.junit.runner.RunWith;

import java.io.DataInput;
import java.io.DataOutput;
Expand All @@ -37,6 +38,7 @@

import static org.junit.Assert.*;

@RunWith(com.hazelcast.util.RandomBlockJUnit4ClassRunner.class)
public class HazelcastClientMapTest extends HazelcastClientTestBase {

@Test(expected = NullPointerException.class)
Expand All @@ -46,6 +48,13 @@ public void testPutNull() {
imap.put(1, null);
}

@Test
public void testDestroy() {
HazelcastClient hClient = getHazelcastClient();
IMap<?,?> map = hClient.getMap("testDestroy");
map.destroy();
}

@Test
public void testIssue508And513() throws Exception {
HazelcastClient client = getHazelcastClient();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import com.hazelcast.impl.base.Values;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;

import java.util.*;
import java.util.Map.Entry;
Expand All @@ -32,6 +33,7 @@

import static org.junit.Assert.*;

@RunWith(com.hazelcast.util.RandomBlockJUnit4ClassRunner.class)
public class HazelcastClientMultiMapTest extends HazelcastClientTestBase {

@Test(expected = NullPointerException.class)
Expand All @@ -41,6 +43,13 @@ public void testPutNull() {
map.put(1, null);
}

@Test
public void testDestroy() {
HazelcastClient hClient = getHazelcastClient();
MultiMap<?, ?> multiMap = hClient.getMultiMap("testDestroy");
multiMap.destroy();
}

@Test
public void putToMultiMap() {
HazelcastClient hClient = getHazelcastClient();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,10 @@

package com.hazelcast.client;

import com.hazelcast.core.HazelcastInstance;
import com.hazelcast.core.IQueue;
import com.hazelcast.core.ItemEvent;
import com.hazelcast.core.ItemListener;
import com.hazelcast.core.*;
import org.junit.AfterClass;
import org.junit.Test;
import org.junit.runner.RunWith;

import java.util.*;
import java.util.concurrent.CountDownLatch;
Expand All @@ -31,6 +29,7 @@
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;

@RunWith(com.hazelcast.util.RandomBlockJUnit4ClassRunner.class)
public class HazelcastClientQueueTest extends HazelcastClientTestBase {

@Test(expected = NullPointerException.class)
Expand All @@ -47,6 +46,13 @@ public void testQueueName() {
assertEquals("testQueueName", queue.getName());
}

@Test
public void testDestroy() {
HazelcastClient hClient = getHazelcastClient();
IQueue<?> queue = hClient.getQueue("testDestroy");
queue.destroy();
}

@Test
public void testQueueOffer() throws InterruptedException {
HazelcastClient hClient = getHazelcastClient();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,7 @@

import com.hazelcast.config.Config;
import com.hazelcast.config.SemaphoreConfig;
import com.hazelcast.core.Hazelcast;
import com.hazelcast.core.HazelcastInstance;
import com.hazelcast.core.ISemaphore;
import com.hazelcast.core.InstanceDestroyedException;
import com.hazelcast.core.*;
import org.junit.*;
import org.junit.runner.RunWith;

Expand Down Expand Up @@ -61,6 +58,14 @@ public void tearDown() throws Exception {
Hazelcast.shutdownAll();
}

@Test
public void testDestroy() {
HazelcastInstance instance = Hazelcast.newHazelcastInstance();
HazelcastClient client = newHazelcastClient(instance);
ISemaphore semaphore = client.getSemaphore("testDestroy");
semaphore.destroy();
}

@Test
public void testSemaphoreWithTimeout() {
SemaphoreConfig semaphoreConfig = new SemaphoreConfig("test", 10);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import org.junit.AfterClass;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;

import java.util.*;
import java.util.concurrent.CountDownLatch;
Expand All @@ -30,6 +31,7 @@

import static org.junit.Assert.*;

@RunWith(com.hazelcast.util.RandomBlockJUnit4ClassRunner.class)
public class HazelcastClientSetTest extends HazelcastClientTestBase {

@Test(expected = NullPointerException.class)
Expand All @@ -46,6 +48,13 @@ public void getSetName() {
assertEquals("getSetName", set.getName());
}

@Test
public void testDestroy() {
HazelcastClient hClient = getHazelcastClient();
ISet<String> set = hClient.getSet("testDestroy");
set.destroy();
}

@Test
public void addRemoveItemListener() throws InterruptedException {
HazelcastClient hClient = getHazelcastClient();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import com.hazelcast.util.Clock;
import org.junit.AfterClass;
import org.junit.Test;
import org.junit.runner.RunWith;

import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutorService;
Expand All @@ -31,6 +32,7 @@
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;

@RunWith(com.hazelcast.util.RandomBlockJUnit4ClassRunner.class)
public class HazelcastClientTopicTest extends HazelcastClientTestBase {

@Test(expected = NullPointerException.class)
Expand All @@ -47,6 +49,13 @@ public void testName() {
assertEquals("testName", topic.getName());
}

@Test
public void testDestroy() {
HazelcastClient hClient = getHazelcastClient();
ITopic<?> topic = hClient.getTopic("testDestroy");
topic.destroy();
}

@Test
public void addMessageListener() throws InterruptedException {
HazelcastClient hClient = getHazelcastClient();
Expand Down
3 changes: 3 additions & 0 deletions hazelcast/src/main/java/com/hazelcast/core/Prefix.java
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,9 @@ public final class Prefix {
*/
public static final String LOCKS_MAP_HAZELCAST = MAP_HAZELCAST + "Locks";


public static final String LOCK = "lock";

/**
* Private constructor to avoid instances of the class.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,14 @@ protected void sendResponse(Packet request) {

private class DestroyHandler extends ClientOperationHandler {
public void processCall(Node node, Packet packet) {
Instance instance = (Instance) factory.getOrCreateProxyByName(packet.name);
String name = packet.name;
Instance instance;
if (Prefix.LOCK.equals(name)) {
Object key = toObject(packet.getKeyData());
instance = (Instance) factory.getOrCreateProxy(new FactoryImpl.ProxyKey(name, key));
} else {
instance = (Instance) factory.getOrCreateProxyByName(name);
}
instance.destroy();
}
}
Expand Down
6 changes: 3 additions & 3 deletions hazelcast/src/main/java/com/hazelcast/impl/FactoryImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -580,7 +580,7 @@ public ILock getLock(Object key) {
if (key == null) {
throw new NullPointerException("Retrieving a lock instance with a null key is not allowed!");
}
return (ILock) getOrCreateProxy(new ProxyKey("lock", key));
return (ILock) getOrCreateProxy(new ProxyKey(Prefix.LOCK, key));
}

public Object getOrCreateProxyByName(final String name) {
Expand Down Expand Up @@ -809,7 +809,7 @@ public Object createProxy(ProxyKey proxyKey) {
proxy = proxyFactory.createSemaphoreProxy(name);
} else if (name.startsWith(Prefix.COUNT_DOWN_LATCH)) {
proxy = proxyFactory.createCountDownLatchProxy(name);
} else if (name.equals("lock")) {
} else if (name.equals(Prefix.LOCK)) {
proxy = proxyFactory.createLockProxy(proxyKey.key);
}
final HazelcastInstanceAwareInstance anotherProxy = proxies.putIfAbsent(proxyKey, proxy);
Expand Down Expand Up @@ -884,7 +884,7 @@ public void process() {
void destroyInstanceClusterWide(String name, Object key) {
final ProxyKey proxyKey = new ProxyKey(name, key);
if (proxies.containsKey(proxyKey)) {
if (name.equals("lock")) {
if (name.equals(Prefix.LOCK)) {
locksMapProxy.remove(key);
}
node.clusterManager.sendProcessableToAll(new CreateOrDestroyInstanceProxy(proxyKey, false), true);
Expand Down
Loading

0 comments on commit 5da3975

Please sign in to comment.