-
Notifications
You must be signed in to change notification settings - Fork 307
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4311 from pzygielo/ut_for_store
UTs for HazelcastTimerStore
- Loading branch information
Showing
5 changed files
with
116 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
...mer/src/test/java/fish/payara/ejb/timer/hazelcast/HazelcastTimerStoreEmptyTimersTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package fish.payara.ejb.timer.hazelcast; | ||
|
||
import java.util.Collection; | ||
import java.util.Collections; | ||
|
||
import org.junit.Test; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
|
||
public class HazelcastTimerStoreEmptyTimersTest extends HazelcastTimerStoreTestBase { | ||
private Collection<HZTimer> timers = Collections.emptyList(); | ||
|
||
@Test | ||
public void emptyTimersShallResultInZeroTimersCountedForServer() { | ||
String [] counts = callListTimers(timers, "a"); | ||
|
||
assertEquals("With no timers defined, zero timers is expected for given server id", "0", counts[0]); | ||
} | ||
|
||
@Test | ||
public void emptyTimersShallResultInArrayOfTheSameSizeAsServerIds() { | ||
String [] counts = callListTimers(timers, "a", "b", "c", "d"); | ||
|
||
assertEquals("Size of counters array shall match the size of server ids array", 4, counts.length); | ||
} | ||
} | ||
|
65 changes: 65 additions & 0 deletions
65
...cast-ejb-timer/src/test/java/fish/payara/ejb/timer/hazelcast/HazelcastTimerStoreTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
package fish.payara.ejb.timer.hazelcast; | ||
|
||
import java.util.Collection; | ||
|
||
import org.junit.Before; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.mockito.Mock; | ||
import org.mockito.runners.MockitoJUnitRunner; | ||
|
||
import static java.util.Arrays.asList; | ||
|
||
import static org.junit.Assert.assertNotNull; | ||
import static org.junit.Assert.assertEquals; | ||
import static org.mockito.Mockito.when; | ||
|
||
@RunWith(MockitoJUnitRunner.class) | ||
public class HazelcastTimerStoreTest extends HazelcastTimerStoreTestBase { | ||
@Mock | ||
private HZTimer timer1, timer2, timer3; | ||
|
||
private Collection<HZTimer> timers; | ||
|
||
@Before | ||
public void setUpTimers() { | ||
timers = asList(timer1, timer2, timer3); | ||
when(timer1.getMemberName()).thenReturn("jb"); | ||
when(timer2.getMemberName()).thenReturn("hz"); | ||
when(timer3.getMemberName()).thenReturn("jb"); | ||
} | ||
|
||
|
||
@Test | ||
public void twoTimersForTheSameMemberNameShallBeCountedForTheSameServerId() { | ||
String [] counts = callListTimers(timers, "jb"); | ||
|
||
assertEquals("2", counts[0]); | ||
} | ||
|
||
@Test | ||
public void countOneTimer() { | ||
String [] counts = callListTimers(timers, "hz"); | ||
|
||
assertEquals("1", counts[0]); | ||
} | ||
|
||
@Test | ||
public void noNullsExpectedInCountsForMissingTimers() { | ||
String [] counts = callListTimers(timers, "jb", "ltd", "hz"); | ||
|
||
for (String count : counts) { | ||
assertNotNull("Even for missing timers/server ids no null is expected but rather some representation of zero", count); | ||
} | ||
} | ||
|
||
@Test | ||
public void countersShallFollowServerIdOrder() { | ||
String [] counts = callListTimers(timers, "hz", "ltd", "jb"); | ||
|
||
assertEquals("1", counts[0]); | ||
assertEquals("0", counts[1]); | ||
assertEquals("2", counts[2]); | ||
} | ||
} | ||
|
10 changes: 10 additions & 0 deletions
10
...-ejb-timer/src/test/java/fish/payara/ejb/timer/hazelcast/HazelcastTimerStoreTestBase.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package fish.payara.ejb.timer.hazelcast; | ||
|
||
import java.util.Collection; | ||
|
||
public abstract class HazelcastTimerStoreTestBase { | ||
public String[] callListTimers(Collection<HZTimer> timers, String... serverIds) { | ||
return HazelcastTimerStore.listTimers(timers, serverIds); | ||
} | ||
} | ||
|