@Test
public void concurrentTest() throws Exception {
final Random rand = new Random();
final AtomicInteger gen = new AtomicInteger();
final ConcurrentTestCase testCase = new ConcurrentTestCase(100, 1000, new ConcurrentTestTask() {
@Override
public void run(final int index, final int times) throws Exception {
final int id = gen.incrementAndGet();
final LocalTransactionId xid = new LocalTransactionId("test", id);
for (int j = 0; j < rand.nextInt(3) + 1; j++) {
final int partition = rand.nextInt(10);
final MessageStore store =
JournalTransactionStoreUnitTest.this.messageStoreManager.getOrCreateMessageStore("topic1",
partition % 10);
JournalTransactionStoreUnitTest.this.transactionStore.addMessage(store, 1, new PutCommand("topic1",
partition, ("msg" + id).getBytes(), xid, 0, 1), null);
}
if (id % 100 == 0) {
JournalTransactionStoreUnitTest.this.journalStore.checkpoint();
}
// commit
JournalTransactionStoreUnitTest.this.transactionStore.commit(xid, false);
}
});
testCase.start();
System.out.println("����ʱ�䣺" + testCase.getDurationInMillis() + "ms");
for (int i = 0; i < 10; i++) {
final MessageStore store = this.messageStoreManager.getOrCreateMessageStore("topic1", i);
assertTrue(store.getSizeInBytes() > 0);
}