@Test
  @MongoDbAvailable
  public void testMessageGroupIterator() throws Exception {
    MongoDbFactory mongoDbFactory = this.prepareMongoFactory();
    MongoDbMessageStore store1 = new MongoDbMessageStore(mongoDbFactory);
    MongoDbMessageStore store2 = new MongoDbMessageStore(mongoDbFactory);

    Message<?> message = new GenericMessage<String>("1");
    store2.addMessageToGroup(1, message);
    store1.addMessageToGroup(2, new GenericMessage<String>("2"));
    store2.addMessageToGroup(3, new GenericMessage<String>("3"));

    MongoDbMessageStore store3 = new MongoDbMessageStore(mongoDbFactory);

    Iterator<MessageGroup> iterator = store3.iterator();
    int counter = 0;
    while (iterator.hasNext()) {
      iterator.next();
      counter++;
    }
    assertEquals(3, counter);

    store2.removeMessageFromGroup(1, message);

    iterator = store3.iterator();
    counter = 0;
    while (iterator.hasNext()) {
      iterator.next();
      counter++;
    }
    assertEquals(2, counter);
  }
  @Test
  @MongoDbAvailable
  public void testRemoveMessageFromTheGroup() throws Exception {
    MongoDbFactory mongoDbFactory = this.prepareMongoFactory();
    MongoDbMessageStore store = new MongoDbMessageStore(mongoDbFactory);

    MessageGroup messageGroup = store.getMessageGroup(1);
    Message<?> message = new GenericMessage<String>("2");
    store.addMessageToGroup(1, new GenericMessage<String>("1"));
    store.addMessageToGroup(1, message);
    messageGroup = store.addMessageToGroup(1, new GenericMessage<String>("3"));

    assertEquals(3, messageGroup.size());

    messageGroup = store.removeMessageFromGroup(1, message);
    assertEquals(2, messageGroup.size());
  }