public void testValidateFailover() throws Exception
{
Connection conn = null;
JVMTIInterface jvmti = new JVMTIInterface();
try
{
conn = cf.createConnection();
conn.close();
conn = cf.createConnection();
conn.start();
// make sure we're connecting to node 1
int nodeID = ((ConnectionState)((DelegateSupport)((JBossConnection)conn).
getDelegate()).getState()).getServerID();
assertEquals(1, nodeID);
Session s1 = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
MessageConsumer c1 = s1.createConsumer(queue[1]);
JBossMessageProducer p1 = (JBossMessageProducer)s1.createProducer(queue[1]);
p1.setDeliveryMode(DeliveryMode.PERSISTENT);
// send a message
p1.send(s1.createTextMessage("blip"));
assertNotNull(c1.receive());
p1.send(s1.createTextMessage("blip again"));
log.info("Producing inventory");
Map inventory1 = jvmti.produceInventory();
// kill node 1
ServerManagement.killAndWait(1);
log.info("########");
log.info("######## KILLED NODE 1");
log.info("########");
try
{
ic[1].lookup("queue"); // looking up anything
fail("The server still alive, kill didn't work yet");
}
catch (Exception e)
{
}
// we must receive the message
TextMessage tm = (TextMessage)c1.receive(1000);
assertEquals("blip again", tm.getText());
log.info("Forcing release on SoftReferences");
jvmti.forceReleaseOnSoftReferences();
jvmti.forceGC();
Map inventory2 = jvmti.produceInventory();
InventoryDataPoint dataPoint = (InventoryDataPoint) inventory2.get(ProducerState.class);
if (dataPoint.getInstances() > 1)
{
// We should only have this producerState... we will look for where are the
// other references
ProducerState originalState = (ProducerState )
((DelegateSupport)p1.getDelegate()).getState();
Object obj[] = jvmti.getAllObjects(ProducerState.class);
for (int i = 0; i < obj.length; i++)
{
if (obj[i] != originalState)
{
log.info("Exploring references on " + obj[i]);
Object[] holders = jvmti.getReferenceHolders(new Object[]{obj[i]});
for (int j = 0; j < holders.length; j++)
{
log.info("Holder[" + j + "] = " + holders[j]);
}
}
}
}
assertTrue("Test produced unexpected objects", jvmti.compareInventories(System.out,
inventory1, inventory2, null, null,
new InventoryDataPoint[]{new InventoryDataPoint(Object.class, 10)}));
}
finally