/** Fake an adhoc compiler result and return it to the CI, see if CI initiates the txn. */ @Test public void testFinishedMPAdHocPlanning() throws Exception { // Need a batch and a statement AdHocPlannedStmtBatch plannedStmtBatch = new AdHocPlannedStmtBatch( "select * from a", null, 0, 0, "localhost", false, ProcedureInvocationType.ORIGINAL, 0, 0, null); AdHocPlannedStatement s = new AdHocPlannedStatement( "select * from a".getBytes(Constants.UTF8ENCODING), new CorePlan( new byte[0], new byte[0], new byte[20], new byte[20], false, false, true, new VoltType[0], 0), ParameterSet.emptyParameterSet(), null, null, null); plannedStmtBatch.addStatement(s); m_ci.processFinishedCompilerWork(plannedStmtBatch).run(); ArgumentCaptor<Long> destinationCaptor = ArgumentCaptor.forClass(Long.class); ArgumentCaptor<Iv2InitiateTaskMessage> messageCaptor = ArgumentCaptor.forClass(Iv2InitiateTaskMessage.class); verify(m_messenger).send(destinationCaptor.capture(), messageCaptor.capture()); Iv2InitiateTaskMessage message = messageCaptor.getValue(); // assertFalse(boolValues.get(0)); // is admin assertTrue(message.isReadOnly()); // readonly assertFalse(message.isSinglePartition()); // single-part // assertFalse(boolValues.get(3)); // every site assertEquals("@AdHoc_RO_MP", message.getStoredProcedureName()); byte[] serializedData = (byte[]) message.getStoredProcedureInvocation().getParameterAtIndex(0); AdHocPlannedStatement[] statements = AdHocPlannedStmtBatch.planArrayFromBuffer(ByteBuffer.wrap(serializedData)); assertEquals(1, statements.length); String sql = new String(statements[0].sql, Constants.UTF8ENCODING); assertEquals("select * from a", sql); }
@Test public void testFinishedSPAdHocPlanning() throws Exception { // Need a batch and a statement AdHocPlannedStmtBatch plannedStmtBatch = new AdHocPlannedStmtBatch( "select * from a where i = 3", 3, 0, 0, "localhost", false, ProcedureInvocationType.ORIGINAL, 0, 0, null); AdHocPlannedStatement s = new AdHocPlannedStatement( "select * from a where i = 3".getBytes(Constants.UTF8ENCODING), new CorePlan( new byte[0], null, new byte[20], null, false, false, true, new VoltType[0], 0), ParameterSet.fromArrayNoCopy(new Object[0]), null, null, 3); plannedStmtBatch.addStatement(s); m_ci.processFinishedCompilerWork(plannedStmtBatch).run(); ArgumentCaptor<Long> destinationCaptor = ArgumentCaptor.forClass(Long.class); ArgumentCaptor<Iv2InitiateTaskMessage> messageCaptor = ArgumentCaptor.forClass(Iv2InitiateTaskMessage.class); verify(m_messenger).send(destinationCaptor.capture(), messageCaptor.capture()); Iv2InitiateTaskMessage message = messageCaptor.getValue(); assertTrue(message.isReadOnly()); // readonly assertTrue(message.isSinglePartition()); // single-part assertEquals("@AdHoc_RO_SP", message.getStoredProcedureName()); // SP AdHoc should have partitioning parameter serialized in the parameter set Object partitionParam = message.getStoredProcedureInvocation().getParameterAtIndex(0); assertTrue(partitionParam instanceof byte[]); VoltType type = VoltType.get((Byte) message.getStoredProcedureInvocation().getParameterAtIndex(1)); assertTrue(type.isInteger()); byte[] serializedData = (byte[]) message.getStoredProcedureInvocation().getParameterAtIndex(2); AdHocPlannedStatement[] statements = AdHocPlannedStmtBatch.planArrayFromBuffer(ByteBuffer.wrap(serializedData)); assertTrue(Arrays.equals(TheHashinator.valueToBytes(3), (byte[]) partitionParam)); assertEquals(1, statements.length); String sql = new String(statements[0].sql, Constants.UTF8ENCODING); assertEquals("select * from a where i = 3", sql); }