final Session session = connection.createSession(true, Session.AUTO_ACKNOWLEDGE);
Destination destination = session.createQueue(name.toString());
MessageProducer producer = session.createProducer(destination);
producer.setDeliveryMode(DeliveryMode.PERSISTENT);
LevelDBStoreViewMBean levelDBView = getLevelDBStoreMBean();
assertNotNull(levelDBView);
levelDBView.compact();
final int SIZE = 6 * 1024 * 5;
final int MSG_COUNT = 60000;
final CountDownLatch done = new CountDownLatch(MSG_COUNT);
byte buffer[] = new byte[SIZE];
for (int i = 0; i < SIZE; ++i) {
buffer[i] = (byte) 128;
}
for (int i = 0; i < MSG_COUNT; ++i) {
BytesMessage message = session.createBytesMessage();
message.writeBytes(buffer);
producer.send(message);
if ((i % 1000) == 0) {
LOG.info("Sent message #{}", i);
session.commit();
}
}
session.commit();
LOG.info("Finished sending all messages.");
MessageConsumer consumer = session.createConsumer(destination);
consumer.setMessageListener(new MessageListener() {
@Override
public void onMessage(Message message) {
if ((done.getCount() % 1000) == 0) {
try {
LOG.info("Received message #{}", MSG_COUNT - done.getCount());
session.commit();
} catch (JMSException e) {
}
}
done.countDown();
}
});
done.await(10, TimeUnit.MINUTES);
session.commit();
LOG.info("Finished receiving all messages.");
LOG.info("Current number of logs {}", countLogFiles());
assertTrue("Should only have one log file left.", Wait.waitFor(new Wait.Condition() {
@Override
public boolean isSatisified() throws Exception {
return countLogFiles() == 1;
}
}, TimeUnit.MINUTES.toMillis(5)));
levelDBView.compact();
LOG.info("Current number of logs {}", countLogFiles());
}