Skip to content

Commit

Permalink
Test MS node name
Browse files Browse the repository at this point in the history
  • Loading branch information
EltonCN committed Dec 11, 2024
1 parent e857da3 commit bb820c7
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ public MemoryStorageCodelet(Mind mind, String nodeName, String mindName,
while (isMemberResult) {
nodeNumber += 1;
nodeName = baseName + Long.toString(nodeNumber);
isMemberResult = commands.sismember(mindNodesPath, nodeName).get();
}
}

Expand Down
29 changes: 26 additions & 3 deletions src/test/java/br/unicamp/cst/memorystorage/MemoryStorageTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ public class MemoryStorageTest {

private Mind mind;
private Mind mind2;
private Mind mind3;

private List<Double> startTimes;
private long sleepTime;
Expand Down Expand Up @@ -62,6 +63,7 @@ public void init() throws Exception {

mind = new Mind();
mind2 = new Mind();
mind3 = new Mind();

Field field = RawMemory.class.getDeclaredField("lastid");
field.setAccessible(true);
Expand All @@ -72,6 +74,7 @@ public void init() throws Exception {
public void tearDown() throws Exception {
mind.shutDown();
mind2.shutDown();
mind3.shutDown();

commands.flushall().get();
}
Expand Down Expand Up @@ -104,6 +107,11 @@ public void testMindName() throws Exception{

@Test
public void nodeEnterTest() throws Exception {
RedisURI uri = RedisURI.Builder
.redis("localhost", 6379)
.build();
RedisClient client = RedisClient.create(uri);

MemoryStorageCodelet msCodelet = new MemoryStorageCodelet(mind);
msCodelet.setTimeStep(50);
mind.insertCodelet(msCodelet);
Expand All @@ -117,19 +125,34 @@ public void nodeEnterTest() throws Exception {
assertEquals(1, members.size());
assertTrue(members.contains("node"));

MemoryStorageCodelet msCodelet2 = new MemoryStorageCodelet(mind2);
MemoryStorageCodelet msCodelet2 = new MemoryStorageCodelet(mind2,"node2", "default_mind", 500.0e-3, client );
msCodelet.setTimeStep(50);
mind2.insertCodelet(msCodelet2);
mind2.start();

Thread.sleep(sleepTime);

assertEquals("node1", msCodelet2.getNodeName());
assertEquals("node2", msCodelet2.getNodeName());

members = commands.smembers("default_mind:nodes").get();
assertEquals(2, members.size());
assertTrue(members.contains("node"));
assertTrue(members.contains("node1"));
assertTrue(members.contains("node2"));

MemoryStorageCodelet msCodelet3 = new MemoryStorageCodelet(mind3);
msCodelet3.setTimeStep(50);
mind3.insertCodelet(msCodelet3);
mind3.start();

Thread.sleep(sleepTime);

assertEquals("node3", msCodelet3.getNodeName());

members = commands.smembers("default_mind:nodes").get();
assertEquals(3, members.size());
assertTrue(members.contains("node"));
assertTrue(members.contains("node2"));
assertTrue(members.contains("node3"));
}

@Test
Expand Down

0 comments on commit bb820c7

Please sign in to comment.