Exemplo n.º 1
0
 @Test
 public void testProduceConsumeMultiMessage() {
   PersistentQueue<Message> queue = new PersistentQueue<Message>("jk.store");
   queue.init();
   for (int i = 0; i < 10; i++) {
     assertTrue(queue.produce(new Message(i)), "always success");
   }
   for (int i = 0; i < 10; i++) {
     Message expected = queue.consume();
     Assert.assertEquals(i, expected.index(), "Comparing index value");
     Assert.assertEquals(
         "My name is JK and I am a crap living in Singapore !@#$$%^^&&",
         expected.value(), "Comparing message value");
   }
   Assert.assertNull(queue.consume(), "Already Popped, so it should not be available");
   queue = new PersistentQueue<Message>("jk.store");
   queue.init();
   Assert.assertNull(queue.consume(), "Already Popped, so it should not be available");
   ////////////////
   queue = new PersistentQueue<Message>("jk.store");
   queue.init();
   for (int i = 11; i <= 20; i++) {
     assertTrue(queue.produce(new Message(i)), "always success");
   }
   for (int i = 11; i <= 20; i++) {
     Message expected = queue.consume();
     Assert.assertEquals(i, expected.index(), "Comparing index value");
     Assert.assertEquals(
         "My name is JK and I am a crap living in Singapore !@#$$%^^&&",
         expected.value(), "Comparing message value");
   }
 }
Exemplo n.º 2
0
  @Test
  public void testProduceConsumeMultiMessageTwoFileOpens() {
    PersistentQueue<Message> queue = new PersistentQueue<Message>("jk.store");
    queue.init();
    for (int i = 0; i < 10; i++) {
      assertTrue(queue.produce(new Message(i)), "always success");
    }
    queue.close();

    queue = new PersistentQueue<Message>("jk.store");
    queue.init();
    for (int i = 0; i < 10; i++) {
      Message expected = queue.consume();
      Assert.assertEquals(i, expected.index(), "Comparing index value");
      Assert.assertEquals(
          "My name is JK and I am a crap living in Singapore !@#$$%^^&&",
          expected.value(), "Comparing message value");
    }
    for (int i = 11; i <= 20; i++) {
      assertTrue(queue.produce(new Message(i)), "always success");
    }
    for (int i = 11; i <= 20; i++) {
      Message expected = queue.consume();
      Assert.assertEquals(i, expected.index(), "Comparing index value");
      Assert.assertEquals(
          "My name is JK and I am a crap living in Singapore !@#$$%^^&&",
          expected.value(), "Comparing message value");
    }
  }
Exemplo n.º 3
0
 @Test
 public void testProduceConsumeSingleMessage() {
   PersistentQueue<Message> queue = new PersistentQueue<Message>("jk.store");
   queue.init();
   final Message actual = new Message(1);
   queue.produce(actual);
   Message expected = queue.consume();
   Assert.assertEquals(actual.index(), expected.index(), "Comparing index value");
   Assert.assertEquals(actual.value(), expected.value(), "Comparing message value");
   Assert.assertNull(queue.consume(), "Already Popped, so it should not be available");
   queue = new PersistentQueue<Message>("jk.store");
   queue.init();
   Assert.assertNull(queue.consume(), "Already Popped, so it should not be available");
 }