Channel channel = new SimpleChannel(0, ms);
IDManager idm = new IDManager("TRANSACTION_ID", 10, pm);
idm.start();
TransactionRepository txRep = new TransactionRepository(pm, ms, idm);
txRep.start();
log.debug("transaction log started");
Message[] messages = createMessages(10);
Message m1 = messages[0];
Message m2 = messages[1];
Message m3 = messages[2];
Message m4 = messages[3];
Message m5 = messages[4];
Transaction tx = null;
if (xa)
{
tx = txRep.createTransaction(new MockXid());
}
else
{
tx = txRep.createTransaction();
}
if (xa)
{
assertEquals(1,txRep.getNumberOfRegisteredTransactions());
}
else
{
assertEquals(0,txRep.getNumberOfRegisteredTransactions());
}
MessageReference ref1 = ms.reference(m1);
MessageReference ref2 = ms.reference(m2);
MessageReference ref3 = ms.reference(m3);
MessageReference ref4 = ms.reference(m4);
MessageReference ref5 = ms.reference(m5);
log.debug("adding references non-transactionally");
// Add first two refs non transactionally
pm.addReference(channel.getChannelID(), ref1, null);
pm.addReference(channel.getChannelID(), ref2, null);
//check they're there
List refs = getReferenceIds(channel.getChannelID());
assertNotNull(refs);
assertEquals(2, refs.size());
assertTrue(refs.contains(new Long(ref1.getMessage().getMessageID())));
assertTrue(refs.contains(new Long(ref2.getMessage().getMessageID())));
List msgs = getMessageIds();
assertNotNull(msgs);
assertEquals(2, msgs.size());
assertTrue(msgs.contains(new Long(ref1.getMessage().getMessageID())));
assertTrue(msgs.contains(new Long(ref2.getMessage().getMessageID())));
log.debug("ref1 and ref2 are there");
//Add the next 3 refs transactionally
pm.addReference(channel.getChannelID(), ref3, tx);
pm.addReference(channel.getChannelID(), ref4, tx);
pm.addReference(channel.getChannelID(), ref5, tx);
//Remove the other 2 transactionally
pm.removeReference(channel.getChannelID(), ref1, tx);
pm.removeReference(channel.getChannelID(), ref2, tx);
//Check the changes aren't visible
refs = getReferenceIds(channel.getChannelID());
assertNotNull(refs);
assertEquals(2, refs.size());
assertTrue(refs.contains(new Long(ref1.getMessage().getMessageID())));
assertTrue(refs.contains(new Long(ref2.getMessage().getMessageID())));
msgs = getMessageIds();
assertNotNull(msgs);
assertEquals(2, msgs.size());
assertTrue(msgs.contains(new Long(ref1.getMessage().getMessageID())));
assertTrue(msgs.contains(new Long(ref2.getMessage().getMessageID())));
//commit transaction
tx.commit();
assertEquals("numberOfRegisteredTransactions",0,txRep.getNumberOfRegisteredTransactions());
//check we can see only the last 3 refs
refs = getReferenceIds(channel.getChannelID());
assertNotNull(refs);
assertEquals(3, refs.size());