this.processor.beginTransaction(context, xid, 0);
this.replay();
this.processor.processPutCommand(new PutCommand("topic1", 2, "hello".getBytes(), xid, 0, 1), context, null);
this.processor.processPutCommand(new PutCommand("topic1", 2, "world".getBytes(), xid, 0, 1), context, null);
MessageStore store = this.messageStoreManager.getOrCreateMessageStore("topic1", 2);
store.flush();
assertEquals(0, store.getSizeInBytes());
assertEquals(0, this.processor.getPreparedTransactions(context, XIDGenerator.UNIQUE_QUALIFIER).length);
// prepare
this.processor.prepareTransaction(context, xid);
assertEquals(1, this.processor.getPreparedTransactions(context, XIDGenerator.UNIQUE_QUALIFIER).length);
assertEquals(1, this.processor.getPreparedTransactions(context, null).length);
assertEquals(0, this.processor.getPreparedTransactions(context, "unknown").length);
assertSame(this.processor.getPreparedTransactions(context, XIDGenerator.UNIQUE_QUALIFIER)[0], this.processor
.getTransaction(context, xid).getTransactionId());
// close and reopen it
this.tearDown();
this.init(this.path);
this.newProcessor();
this.processor.recoverPreparedTransactions();
assertEquals(1, this.processor.getPreparedTransactions(context, XIDGenerator.UNIQUE_QUALIFIER).length);
assertEquals(1, this.processor.getPreparedTransactions(context, null).length);
assertEquals(0, this.processor.getPreparedTransactions(context, "unknown").length);
assertSame(this.processor.getPreparedTransactions(context, XIDGenerator.UNIQUE_QUALIFIER)[0], this.processor
.getTransaction(context, xid).getTransactionId());
store = this.messageStoreManager.getOrCreateMessageStore("topic1", 2);
store.flush();
assertEquals(0, store.getSizeInBytes());
// commit two phase
this.processor.commitTransaction(context, xid, false);
store.flush();
assertEquals(0, this.processor.getPreparedTransactions(context, XIDGenerator.UNIQUE_QUALIFIER).length);
assertNull(context.getTransactions().get(xid));
store.flush();
assertTrue(store.getSizeInBytes() > 0);
}