Skip to content

Commit

Permalink
Change DistributedHashtable constructor from JChannel to Channel
Browse files Browse the repository at this point in the history
Copy DistributedHashtableUnitTest from 2.5 branch
update eclipse classpath to include conf dir
  • Loading branch information
Vladimir Blagojevic committed Apr 26, 2007
1 parent 08995c4 commit 818664d
Show file tree
Hide file tree
Showing 3 changed files with 164 additions and 27 deletions.
1 change: 1 addition & 0 deletions .classpath
@@ -1,6 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry excluding="**/obsolete/*" kind="src" path="src"/>
<classpathentry kind="src" path="conf"/>
<classpathentry excluding="**/obsolete/*" kind="src" path="tests/junit"/>
<classpathentry excluding="**/obsolete/*" kind="src" path="tests/other"/>
<classpathentry excluding="**/obsolete/*" kind="src" path="tests/perf"/>
Expand Down
8 changes: 4 additions & 4 deletions src/org/jgroups/blocks/DistributedHashtable.java
@@ -1,4 +1,4 @@
// $Id: DistributedHashtable.java,v 1.26.2.1 2007/03/13 14:50:51 belaban Exp $
// $Id: DistributedHashtable.java,v 1.26.2.2 2007/04/26 16:43:00 vlada Exp $

package org.jgroups.blocks;

Expand Down Expand Up @@ -35,7 +35,7 @@
* initial state (using the state exchange funclet <code>StateExchangeFunclet</code>.
* @author Bela Ban
* @author <a href="mailto:aolias@yahoo.com">Alfonso Olias-Sanz</a>
* @version $Id: DistributedHashtable.java,v 1.26.2.1 2007/03/13 14:50:51 belaban Exp $
* @version $Id: DistributedHashtable.java,v 1.26.2.2 2007/04/26 16:43:00 vlada Exp $
*/
public class DistributedHashtable extends Hashtable implements MessageListener, MembershipListener {

Expand Down Expand Up @@ -126,12 +126,12 @@ public DistributedHashtable(String groupname, ChannelFactory factory, String pro
}


public DistributedHashtable(JChannel channel, long state_timeout) {
public DistributedHashtable(Channel channel, long state_timeout) {
this(channel, false, state_timeout);
}


public DistributedHashtable(JChannel channel, boolean persistent, long state_timeout) {
public DistributedHashtable(Channel channel, boolean persistent, long state_timeout) {
this.groupname = channel.getClusterName();
this.channel = channel;
this.persistent=persistent;
Expand Down
182 changes: 159 additions & 23 deletions tests/junit/org/jgroups/tests/DistributedHashtableUnitTest.java
@@ -1,21 +1,19 @@
package org.jgroups.tests;

import junit.framework.TestCase;
import org.jgroups.JChannel;
import org.jgroups.Channel;
import org.jgroups.blocks.DistributedHashtable;

import java.net.URL;
import java.util.HashMap;
import java.util.Map;

/**
*
* @author Bela Ban belaban@yahoo.com
* @version $Revision: 1.2.2.2 $
* Test methods for DistributedHashtable
* @author denis.pasek@senacor.com
* @version $Revision: 1.2.2.3 $
**/
public class DistributedHashtableUnitTest extends TestCase {
public class DistributedHashtableUnitTest extends ChannelTestBase {

private static int testCount = 1;

private static final String props="c:\\udp-2.4.xml";
private static int testCount = 1;

private DistributedHashtable map1;
private DistributedHashtable map2;
Expand All @@ -24,29 +22,132 @@ public DistributedHashtableUnitTest(String testName) {
super(testName);
}

protected void setUp() throws Exception {
public void setUp() throws Exception {
super.setUp();
System.out.println("#### Setup Test " + testCount);

JChannel c1=new JChannel(props);
Channel c1=createChannel("A");
this.map1=new DistributedHashtable(c1, false, 5000);
c1.connect("demo");
this.map1.start(5000);

JChannel c2=new JChannel(props);
Channel c2=createChannel("A");
this.map2=new DistributedHashtable(c2, false, 5000);
c2.connect("demo");
this.map2.start(5000);
}

protected void tearDown() throws Exception {
public void tearDown() throws Exception {
this.map1.stop();
this.map2.stop();
System.out.println("#### TearDown Test " + testCount + "\n\n");
testCount++;
super.tearDown();
}

public void testSize() {
assertEquals(0, this.map1.size());
assertEquals(this.map2.size(), this.map1.size());

this.map1.put("key1", "value1");
assertEquals(1, this.map1.size());
assertEquals(this.map2.size(), this.map1.size());

this.map2.put("key2", "value2");
assertEquals(2, this.map1.size());
assertEquals(this.map2.size(), this.map1.size());
}

public void testIsEmpty() {
assertTrue(this.map1.isEmpty());
assertTrue(this.map2.isEmpty());

this.map1.put("key", "value");

assertFalse(this.map1.isEmpty());
assertFalse(this.map2.isEmpty());
}

public void testContainsKey() {
assertFalse(this.map1.containsKey("key1"));
assertFalse(this.map2.containsKey("key1"));
this.map1.put("key1", "value");
assertTrue(this.map1.containsKey("key1"));
assertTrue(this.map2.containsKey("key1"));
this.map2.put("key2", "value");
assertTrue(this.map1.containsKey("key2"));
assertTrue(this.map2.containsKey("key2"));
}

public void testContainsValue() {
assertFalse(this.map1.containsValue("value1"));
assertFalse(this.map2.containsValue("value1"));
this.map1.put("key1", "value1");
assertTrue(this.map1.containsValue("value1"));
assertTrue(this.map2.containsValue("value1"));
this.map2.put("key2", "value2");
assertTrue(this.map1.containsValue("value2"));
assertTrue(this.map2.containsValue("value2"));
}

public void testPutAndGet() {
assertNull(this.map1.get("key1"));
assertNull(this.map2.get("key1"));
this.map1.put("key1", "value1");
assertNotNull(this.map1.get("key1"));
assertNotNull(this.map2.get("key1"));
this.map2.put("key2", "value2");
assertNotNull(this.map1.get("key2"));
assertNotNull(this.map2.get("key2"));
}

public void testRemove() {
assertNull(this.map1.get("key1"));
assertNull(this.map2.get("key1"));
this.map1.put("key1", "value1");
this.map2.put("key2", "value2");
assertNotNull(this.map1.get("key1"));
assertNotNull(this.map2.get("key1"));
assertNotNull(this.map1.get("key2"));
assertNotNull(this.map2.get("key2"));

this.map1.remove("key1");
assertNull(this.map1.get("key1"));
assertNull(this.map2.get("key1"));
assertNotNull(this.map1.get("key2"));
assertNotNull(this.map2.get("key2"));

this.map2.remove("key2");
assertNull(this.map1.get("key2"));
assertNull(this.map2.get("key2"));
}

public void testPutAll() {
Map all1 = new HashMap();
all1.put("key1", "value1");
all1.put("key2", "value2");
Map all2 = new HashMap();
all2.put("key3", "value3");
all2.put("key4", "value4");

this.map1.putAll(all1);
assertEquals(2, this.map1.size());
assertEquals(2, this.map2.size());
this.map2.putAll(all2);
assertEquals(4, this.map1.size());
assertEquals(4, this.map2.size());

assertTrue(this.map1.containsKey("key1"));
assertTrue(this.map1.containsKey("key2"));
assertTrue(this.map1.containsKey("key3"));
assertTrue(this.map1.containsKey("key4"));

assertTrue(this.map2.containsKey("key1"));
assertTrue(this.map2.containsKey("key2"));
assertTrue(this.map2.containsKey("key3"));
assertTrue(this.map2.containsKey("key4"));
}

public void testClear() {
assertTrue(this.map1.isEmpty());
assertTrue(this.map2.isEmpty());
Expand All @@ -58,16 +159,51 @@ public void testClear() {
this.map1.clear();
assertTrue(this.map1.isEmpty());
assertTrue(this.map2.isEmpty());
/*
this.map2.put("key", "value");
assertFalse(this.map1.isEmpty());
assertFalse(this.map2.isEmpty());
this.map2.clear();
assertTrue(this.map1.isEmpty());
assertTrue(this.map2.isEmpty());
*/
this.map2.put("key", "value");
assertFalse(this.map1.isEmpty());
assertFalse(this.map2.isEmpty());

this.map2.clear();
assertTrue(this.map1.isEmpty());
assertTrue(this.map2.isEmpty());
}

public void testKeySet() {
Map all1 = new HashMap();
all1.put("key1", "value1");
all1.put("key2", "value2");
Map all2 = new HashMap();
all2.put("key3", "value3");
all2.put("key4", "value4");

this.map1.putAll(all1);
assertEquals(all1.keySet(), this.map1.keySet());
assertEquals(all1.keySet(), this.map2.keySet());

this.map2.putAll(all2);
all1.putAll(all2);
assertEquals(all1.keySet(), this.map1.keySet());
assertEquals(all1.keySet(), this.map2.keySet());
}

public void testValues() {
Map all1 = new HashMap();
all1.put("key1", "value1");
all1.put("key2", "value2");
Map all2 = new HashMap();
all2.put("key3", "value3");
all2.put("key4", "value4");

this.map1.putAll(all1);
assertTrue(this.map1.values().containsAll(all1.values()));
assertTrue(this.map2.values().containsAll(all1.values()));

this.map2.putAll(all2);
all1.putAll(all2);
assertTrue(this.map1.values().containsAll(all1.values()));
assertTrue(this.map2.values().containsAll(all1.values()));
}



}

0 comments on commit 818664d

Please sign in to comment.