private void helpTestNextBatch(int[] commandsPerPlan) throws Exception { List plans = new ArrayList(commandsPerPlan.length); int totalCommands = 0; for (int i = 0; i < commandsPerPlan.length; i++) { totalCommands += commandsPerPlan[i]; plans.add(new FakeProcessorPlan(commandsPerPlan[i])); } BatchedUpdatePlan plan = new BatchedUpdatePlan(plans, totalCommands, null, false); plan.initialize(new CommandContext(), null, null); TupleBatch batch = plan.nextBatch(); assertEquals(totalCommands, batch.getRowCount()); for (int i = 1; i <= totalCommands; i++) { assertEquals(new Integer(1), batch.getTuple(i).get(0)); } }
@Test public void testOpen() throws Exception { FakeProcessorPlan[] plans = new FakeProcessorPlan[4]; for (int i = 0; i < plans.length; i++) { plans[i] = new FakeProcessorPlan(1); } BatchedUpdatePlan plan = new BatchedUpdatePlan(Arrays.asList(plans), plans.length, null, false); plan.initialize(new CommandContext(), null, null); plan.open(); // First plan may or may not be opened, but all subsequent plans should not be opened. for (int i = 1; i < plans.length; i++) { assertFalse(plans[i].isOpened()); } }
plan.initialize(context, null, null); plan.open();
@Test public void testMultipleBatches() throws Exception { FakeProcessorPlan[] plans = new FakeProcessorPlan[4]; for (int i = 0; i < plans.length; i++) { TupleBatch last = new TupleBatch(2, Arrays.asList(Arrays.asList(1))); last.setTerminationFlag(true); plans[i] = new FakeProcessorPlan(Arrays.asList(Command.getUpdateCommandSymbol()), Arrays.asList(new TupleBatch(1, Arrays.asList(Arrays.asList(1))), BlockedException.INSTANCE, last)); } BatchedUpdatePlan plan = new BatchedUpdatePlan(Arrays.asList(plans), plans.length*2, null, false); plan.initialize(new CommandContext(), null, null); plan.open(); // First plan may or may not be opened, but all subsequent plans should not be opened. for (int i = 1; i < plans.length; i++) { assertFalse(plans[i].isOpened()); } for (int i = 0; i < 4; i++) { try { plan.nextBatch(); fail(); } catch (BlockedException e) { } } TupleBatch batch = plan.nextBatch(); assertEquals(8, batch.getRowCount()); assertTrue(batch.getTerminationFlag()); }