/**
* Tests that variables introduced in one query are not available in the next
*/
@Test
public void testQueryIsolation() throws Exception {
final RexsterClient client = getClient();
RexProMessage inMsg;
//create a session
final SessionRequestMessage outMsg = new SessionRequestMessage();
outMsg.setRequestAsUUID(UUID.randomUUID());
inMsg = client.execute(outMsg);
Assert.assertNotNull(inMsg.Session);
Assert.assertTrue(inMsg instanceof SessionResponseMessage);
UUID sessionKey = BitWorks.convertByteArrayToUUID(inMsg.Session);
//test that it works
final ScriptRequestMessage scriptMessage = new ScriptRequestMessage();
scriptMessage.Script = "n = 5\nn";
scriptMessage.LanguageName = "groovy";
scriptMessage.metaSetInSession(true);
scriptMessage.setRequestAsUUID(UUID.randomUUID());
scriptMessage.Session = BitWorks.convertUUIDToByteArray(sessionKey);
inMsg = client.execute(scriptMessage);
Assert.assertTrue(inMsg instanceof ScriptResponseMessage);
Assert.assertTrue(((ScriptResponseMessage) inMsg).Results.get() != null);
// test that 'n' is not available if the isolate meta flag is not set to false
final ScriptRequestMessage scriptMessage2 = new ScriptRequestMessage();
scriptMessage2.Script = "m = n + 1";
scriptMessage2.LanguageName = "groovy";
scriptMessage2.metaSetInSession(true);
scriptMessage2.setRequestAsUUID(UUID.randomUUID());
scriptMessage2.Session = BitWorks.convertUUIDToByteArray(sessionKey);
inMsg = client.execute(scriptMessage2);
Assert.assertTrue(inMsg instanceof ErrorResponseMessage);
Assert.assertEquals(((ErrorResponseMessage) inMsg).metaGetFlag(), ErrorResponseMessage.SCRIPT_FAILURE_ERROR);
}