@Test public void testShardCommandManagerNormalWithCancel() throws IOException, TimeoutException, ExceptionCollector, BlurException, InterruptedException { String commandExecutionId = "TEST_COMMAND_ID1"; BlurObjectSerDe serDe = new BlurObjectSerDe(); WaitForSeconds waitForSeconds = new WaitForSeconds(); waitForSeconds.setTable("test"); waitForSeconds.setSeconds(5); waitForSeconds.setCommandExecutionId(commandExecutionId); Arguments arguments = CommandUtil.toArguments(waitForSeconds, serDe); BlurObject args = CommandUtil.toBlurObject(arguments); System.out.println(args.toString(1)); final ArgumentOverlay argumentOverlay = new ArgumentOverlay(args, serDe); final AtomicBoolean fail = new AtomicBoolean(); final AtomicBoolean running = new AtomicBoolean(true); new Thread(new Runnable() { @Override public void run() { TableContextFactory tableContextFactory = getTableContextFactory(); Long instanceExecutionId = null; while (true) { try { Response response; if (instanceExecutionId == null) { CommandStatus originalCommandStatusObject = new CommandStatus(null, "test", null, null, null); response = _manager.execute(tableContextFactory, "wait", argumentOverlay, originalCommandStatusObject); } else { response = _manager.reconnect(instanceExecutionId); } fail.set(true); System.out.println(response); return; } catch (IOException e) { if (e.getCause() instanceof CancellationException) { return; } e.printStackTrace(); fail.set(true); return; } catch (TimeoutException e) { instanceExecutionId = e.getInstanceExecutionId(); } catch (Exception e) { e.printStackTrace(); fail.set(true); return; } finally { running.set(false); } } } }).start(); Thread.sleep(1000); _manager.cancelCommand(commandExecutionId); Thread.sleep(5000); if (fail.get() || running.get()) { fail("Fail [" + fail.get() + "] Running [" + running.get() + "]"); } }
public Response execute(final TableContextFactory tableContextFactory, final String commandName, final ArgumentOverlay argumentOverlay, CommandStatus originalCommandStatusObject) throws IOException, TimeoutException, ExceptionCollector { final ShardServerContext shardServerContext = getShardServerContext(); AtomicBoolean running = new AtomicBoolean(true); final Command<?> command = getCommandObject(commandName, argumentOverlay); Callable<Response> callable = new Callable<Response>() { @Override public Response call() throws Exception { if (command == null) { throw new IOException("Command with name [" + commandName + "] not found."); } if (command instanceof IndexRead || command instanceof ServerRead) { return toResponse( executeReadCommand(shardServerContext, command, tableContextFactory, originalCommandStatusObject, running), command, getServerContext(tableContextFactory)); } throw new IOException("Command type of [" + command.getClass() + "] not supported."); } private CombiningContext getServerContext(final TableContextFactory tableContextFactory) { return new CombiningContext() { @Override public TableContext getTableContext(String table) throws IOException { return tableContextFactory.getTableContext(table); } @Override public BlurConfiguration getBlurConfiguration(String table) throws IOException { return getTableContext(table).getBlurConfiguration(); } }; } }; return submitDriverCallable(callable, command, originalCommandStatusObject, running); }
ShardCommandManager extends BaseCommandManager { public Response execute(final TableContextFactory tableContextFactory, final String commandName, final ArgumentOverlay argumentOverlay, CommandStatus originalCommandStatusObject) throws IOException, TimeoutException, ExceptionCollector { final ShardServerContext shardServerContext = getShardServerContext(); AtomicBoolean running = new AtomicBoolean(true); final Command<?> command = getCommandObject(commandName, argumentOverlay); Callable<Response> callable = new Callable<Response>() { @Override public Response call() throws Exception { if (command == null) { throw new IOException("Command with name [" + commandName + "] not found."); } if (command instanceof IndexRead || command instanceof ServerRead) { return toResponse( executeReadCommand(shardServerContext, command, tableContextFactory, originalCommandStatusObject, running), command, getServerContext(tableContextFactory)); } throw new IOException("Command type of [" + command.getClass() + "] not supported."); } private CombiningContext getServerContext(final TableContextFactory tableContextFactory) { return new CombiningContext() { @Override public TableContext getTableContext(String table) throws IOException { return tableContextFactory.getTableContext(table); } @Override public BlurConfiguration getBlurConfiguration(String table) throws IOException { return getTableContext(table).getBlurConfiguration(); } }; } }; return submitDriverCallable(callable, command, originalCommandStatusObject, running); } }
ShardCommandManager extends BaseCommandManager { public Response execute(final TableContextFactory tableContextFactory, final String commandName, final ArgumentOverlay argumentOverlay, CommandStatus originalCommandStatusObject) throws IOException, TimeoutException, ExceptionCollector { final ShardServerContext shardServerContext = getShardServerContext(); AtomicBoolean running = new AtomicBoolean(true); final Command<?> command = getCommandObject(commandName, argumentOverlay); Callable<Response> callable = new Callable<Response>() { @Override public Response call() throws Exception { if (command == null) { throw new IOException("Command with name [" + commandName + "] not found."); } if (command instanceof IndexRead || command instanceof ServerRead) { return toResponse( executeReadCommand(shardServerContext, command, tableContextFactory, originalCommandStatusObject, running), command, getServerContext(tableContextFactory)); } throw new IOException("Command type of [" + command.getClass() + "] not supported."); } private CombiningContext getServerContext(final TableContextFactory tableContextFactory) { return new CombiningContext() { @Override public TableContext getTableContext(String table) throws IOException { return tableContextFactory.getTableContext(table); } @Override public BlurConfiguration getBlurConfiguration(String table) throws IOException { return getTableContext(table).getBlurConfiguration(); } }; } }; return submitDriverCallable(callable, command, originalCommandStatusObject, running); } ShardCommandManager(IndexServer indexServer, File tmpPath, String commandPath, int workerThreadCount,
      int driverThreadCount, long connectionTimeout, Configuration configuration, String serverName); }
ShardCommandManager extends BaseCommandManager { public Response execute(final TableContextFactory tableContextFactory, final String commandName, final ArgumentOverlay argumentOverlay, CommandStatus originalCommandStatusObject) throws IOException, TimeoutException, ExceptionCollector { final ShardServerContext shardServerContext = getShardServerContext(); AtomicBoolean running = new AtomicBoolean(true); final Command<?> command = getCommandObject(commandName, argumentOverlay); Callable<Response> callable = new Callable<Response>() { @Override public Response call() throws Exception { if (command == null) { throw new IOException("Command with name [" + commandName + "] not found."); } if (command instanceof IndexRead || command instanceof ServerRead) { return toResponse( executeReadCommand(shardServerContext, command, tableContextFactory, originalCommandStatusObject, running), command, getServerContext(tableContextFactory)); } throw new IOException("Command type of [" + command.getClass() + "] not supported."); } private CombiningContext getServerContext(final TableContextFactory tableContextFactory) { return new CombiningContext() { @Override public TableContext getTableContext(String table) throws IOException { return tableContextFactory.getTableContext(table); } @Override public BlurConfiguration getBlurConfiguration(String table) throws IOException { return getTableContext(table).getBlurConfiguration(); } }; } }; return submitDriverCallable(callable, command, originalCommandStatusObject, running); } ShardCommandManager(IndexServer indexServer, File tmpPath, String commandPath, int workerThreadCount,
      int driverThreadCount, long connectionTimeout, Configuration configuration, String serverName); Response execute(final TableContextFactory tableContextFactory, final String commandName,
      final ArgumentOverlay argumentOverlay, CommandStatus originalCommandStatusObject); }
ShardCommandManager extends BaseCommandManager { public Response execute(final TableContextFactory tableContextFactory, final String commandName, final ArgumentOverlay argumentOverlay, CommandStatus originalCommandStatusObject) throws IOException, TimeoutException, ExceptionCollector { final ShardServerContext shardServerContext = getShardServerContext(); AtomicBoolean running = new AtomicBoolean(true); final Command<?> command = getCommandObject(commandName, argumentOverlay); Callable<Response> callable = new Callable<Response>() { @Override public Response call() throws Exception { if (command == null) { throw new IOException("Command with name [" + commandName + "] not found."); } if (command instanceof IndexRead || command instanceof ServerRead) { return toResponse( executeReadCommand(shardServerContext, command, tableContextFactory, originalCommandStatusObject, running), command, getServerContext(tableContextFactory)); } throw new IOException("Command type of [" + command.getClass() + "] not supported."); } private CombiningContext getServerContext(final TableContextFactory tableContextFactory) { return new CombiningContext() { @Override public TableContext getTableContext(String table) throws IOException { return tableContextFactory.getTableContext(table); } @Override public BlurConfiguration getBlurConfiguration(String table) throws IOException { return getTableContext(table).getBlurConfiguration(); } }; } }; return submitDriverCallable(callable, command, originalCommandStatusObject, running); } ShardCommandManager(IndexServer indexServer, File tmpPath, String commandPath, int workerThreadCount,
      int driverThreadCount, long connectionTimeout, Configuration configuration, String serverName); Response execute(final TableContextFactory tableContextFactory, final String commandName,
      final ArgumentOverlay argumentOverlay, CommandStatus originalCommandStatusObject);  }