Skip to content

Commit

Permalink
MAILBOX-267 simplify tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mbaechler committed May 2, 2016
1 parent 8eb0a5e commit f1d8c0d
Showing 1 changed file with 21 additions and 60 deletions.
Expand Up @@ -49,79 +49,47 @@ public class CassandraUidAndModSeqProviderTest {
new CassandraAclModule(), new CassandraAclModule(),
new CassandraMailboxModule(), new CassandraMailboxModule(),
new CassandraUidAndModSeqModule())); new CassandraUidAndModSeqModule()));
private static final int NAMESPACES = 5;
private static final int USERS = 5;
private static final int MAILBOX_NO = 5;
private static final int MAX_RETRY = 100; private static final int MAX_RETRY = 100;
private static final char SEPARATOR = '%';


private CassandraUidProvider uidProvider; private CassandraUidProvider uidProvider;
private CassandraModSeqProvider modSeqProvider; private CassandraModSeqProvider modSeqProvider;
private CassandraMailboxMapper mapper; private CassandraMailboxMapper mapper;
private List<SimpleMailbox<CassandraId>> mailboxList; private SimpleMailbox<CassandraId> mailbox;
private List<MailboxPath> pathsList;


@Before @Before
public void setUpClass() throws Exception { public void setUpClass() throws Exception {
CASSANDRA.ensureAllTables(); CASSANDRA.ensureAllTables();
uidProvider = new CassandraUidProvider(CASSANDRA.getConf()); uidProvider = new CassandraUidProvider(CASSANDRA.getConf());
modSeqProvider = new CassandraModSeqProvider(CASSANDRA.getConf()); modSeqProvider = new CassandraModSeqProvider(CASSANDRA.getConf());
mapper = new CassandraMailboxMapper(CASSANDRA.getConf(), CASSANDRA.getTypesProvider(), MAX_RETRY); mapper = new CassandraMailboxMapper(CASSANDRA.getConf(), CASSANDRA.getTypesProvider(), MAX_RETRY);
fillMailboxList(); MailboxPath path = new MailboxPath("gsoc", "ieugen", "Trash");
for (SimpleMailbox<CassandraId> mailbox : mailboxList) { mailbox = new SimpleMailbox<>(path, 1234);
mapper.save(mailbox); mapper.save(mailbox);
}
} }


@After @After
public void cleanUp() { public void cleanUp() {
CASSANDRA.clearAllTables(); CASSANDRA.clearAllTables();
} }


private void fillMailboxList() {
mailboxList = new ArrayList<>();
pathsList = new ArrayList<>();
MailboxPath path;
String name;
for (int i = 0; i < NAMESPACES; i++) {
for (int j = 0; j < USERS; j++) {
for (int k = 0; k < MAILBOX_NO; k++) {
if (j == 3) {
name = "test" + SEPARATOR + "subbox" + k;
} else {
name = "mailbox" + k;
}
path = new MailboxPath("namespace" + i, "user" + j, name);
pathsList.add(path);
mailboxList.add(new SimpleMailbox<>(path, 13));
}
}
}
}

@Test @Test
public void lastUidShouldRetrieveValueStoredByNextUid() throws Exception { public void lastUidShouldRetrieveValueStoredByNextUid() throws Exception {
MailboxPath path = new MailboxPath("gsoc", "ieugen", "Trash"); int nbEntries = 100;
SimpleMailbox<CassandraId> newBox = new SimpleMailbox<>(path, 1234); long result = uidProvider.lastUid(null, mailbox);
mapper.save(newBox);
mailboxList.add(newBox);
pathsList.add(path);

long result = uidProvider.lastUid(null, newBox);
assertEquals(0, result); assertEquals(0, result);
LongStream.range(1, 10) LongStream.range(0, nbEntries)
.forEach(Throwing.longConsumer(value -> { .forEach(Throwing.longConsumer(value -> {
long uid = uidProvider.nextUid(null, newBox); long uid = uidProvider.nextUid(null, mailbox);
assertThat(uid).isEqualTo(uidProvider.lastUid(null, newBox)); assertThat(uid).isEqualTo(uidProvider.lastUid(null, mailbox));
}) })
); );
} }


@Test @Test
public void nextUidShouldIncrementValueByOne() throws Exception { public void nextUidShouldIncrementValueByOne() throws Exception {
SimpleMailbox<CassandraId> mailbox = mailboxList.get(mailboxList.size() / 2); int nbEntries = 100;
long lastUid = uidProvider.lastUid(null, mailbox); long lastUid = uidProvider.lastUid(null, mailbox);
LongStream.range(lastUid + 1, lastUid + 10) LongStream.range(lastUid + 1, lastUid + nbEntries)
.forEach(Throwing.longConsumer(value -> { .forEach(Throwing.longConsumer(value -> {
long result = uidProvider.nextUid(null, mailbox); long result = uidProvider.nextUid(null, mailbox);
assertThat(value).isEqualTo(result); assertThat(value).isEqualTo(result);
Expand All @@ -131,27 +99,22 @@ public void nextUidShouldIncrementValueByOne() throws Exception {


@Test @Test
public void highestModSeqShouldRetrieveValueStoredNextModSeq() throws Exception { public void highestModSeqShouldRetrieveValueStoredNextModSeq() throws Exception {
MailboxPath path = new MailboxPath("gsoc", "ieugen", "Trash"); int nbEntries = 100;
SimpleMailbox<CassandraId> newBox = new SimpleMailbox<>(path, 1234); long result = modSeqProvider.highestModSeq(null, mailbox);
mapper.save(newBox);
mailboxList.add(newBox);
pathsList.add(path);

long result = modSeqProvider.highestModSeq(null, newBox);
assertEquals(0, result); assertEquals(0, result);
LongStream.range(1, 10) LongStream.range(0, nbEntries)
.forEach(Throwing.longConsumer(value -> { .forEach(Throwing.longConsumer(value -> {
long uid = modSeqProvider.nextModSeq(null, newBox); long uid = modSeqProvider.nextModSeq(null, mailbox);
assertThat(uid).isEqualTo(modSeqProvider.highestModSeq(null, newBox)); assertThat(uid).isEqualTo(modSeqProvider.highestModSeq(null, mailbox));
}) })
); );
} }


@Test @Test
public void nextModSeqShouldIncrementValueByOne() throws Exception { public void nextModSeqShouldIncrementValueByOne() throws Exception {
SimpleMailbox<CassandraId> mailbox = mailboxList.get(mailboxList.size() / 2); int nbEntries = 100;
long lastUid = modSeqProvider.highestModSeq(null, mailbox); long lastUid = modSeqProvider.highestModSeq(null, mailbox);
LongStream.range(lastUid + 1, lastUid + 10) LongStream.range(lastUid + 1, lastUid + nbEntries)
.forEach(Throwing.longConsumer(value -> { .forEach(Throwing.longConsumer(value -> {
long result = modSeqProvider.nextModSeq(null, mailbox); long result = modSeqProvider.nextModSeq(null, mailbox);
assertThat(value).isEqualTo(result); assertThat(value).isEqualTo(result);
Expand All @@ -161,8 +124,7 @@ public void nextModSeqShouldIncrementValueByOne() throws Exception {


@Test @Test
public void nextModSeqShouldGenerateUniqueValuesWhenParallelCalls() throws Exception { public void nextModSeqShouldGenerateUniqueValuesWhenParallelCalls() throws Exception {
SimpleMailbox<CassandraId> mailbox = mailboxList.get(mailboxList.size() / 2); int nbEntries = 100;
int nbEntries = 1000;
long nbValues = LongStream.range(0, nbEntries) long nbValues = LongStream.range(0, nbEntries)
.parallel() .parallel()
.map(Throwing.longUnaryOperator(x -> modSeqProvider.nextModSeq(null, mailbox))) .map(Throwing.longUnaryOperator(x -> modSeqProvider.nextModSeq(null, mailbox)))
Expand All @@ -173,8 +135,7 @@ public void nextModSeqShouldGenerateUniqueValuesWhenParallelCalls() throws Excep


@Test @Test
public void nextUidShouldGenerateUniqueValuesWhenParallelCalls() throws Exception { public void nextUidShouldGenerateUniqueValuesWhenParallelCalls() throws Exception {
SimpleMailbox<CassandraId> mailbox = mailboxList.get(mailboxList.size() / 2); int nbEntries = 100;
int nbEntries = 1000;
long nbValues = LongStream.range(0, nbEntries) long nbValues = LongStream.range(0, nbEntries)
.parallel() .parallel()
.map(Throwing.longUnaryOperator(x -> uidProvider.nextUid(null, mailbox))) .map(Throwing.longUnaryOperator(x -> uidProvider.nextUid(null, mailbox)))
Expand Down

0 comments on commit f1d8c0d

Please sign in to comment.