@Override public void run() { LOG.info("Running"); try { // Just throw some exception and log it try { throw new Exception("Exception"); } catch (Exception e) { throw new RuntimeException(e); } } catch (Throwable t) { LOG.error("Got exception", t); } // Announce so that test case knows the code reaches here. getContext().announce("log", 12345); Uninterruptibles.awaitUninterruptibly(stopLatch); }
@Override public void run() { // This heap size should be > 16, since the min allocation size is 128mb if (Runtime.getRuntime().maxMemory() <= 16 * 1024 * 1024) { LOG.error("Memory size is too small: {}", Runtime.getRuntime().maxMemory()); return; } runThread = Thread.currentThread(); getContext().announce("sleep", Integer.parseInt(getContext().getSpecification().getConfigs().get("port"))); try { TimeUnit.SECONDS.sleep(120); } catch (InterruptedException e) { // Ignore. } }
@Override public void run() { String runnableName = getContext().getSpecification().getName(); String serviceName = System.getProperty("service.name"); LOG.info("Announcing with name {} for runnable {}", serviceName, runnableName); // Compute a unique port name based on runnable name (running names are r[0-9]+) getContext().announce(serviceName, 12345 + Integer.parseInt(runnableName.substring(1))); try { stopLatch.await(); } catch (InterruptedException e) { LOG.warn("Run thread interrupted", e); } }
@Override public void run() { runThread = Thread.currentThread(); getContext().announce("sleep", Integer.parseInt(getContext().getSpecification().getConfigs().get("port"))); try { TimeUnit.SECONDS.sleep(120); } catch (InterruptedException e) { // Ignore. } }
@Override public void initialize(TwillContext context) { super.initialize(context); running = true; try { serverSocket = new ServerSocket(0); LOG.info("Server started: " + serverSocket.getLocalSocketAddress() + ", id: " + context.getInstanceId() + ", count: " + context.getInstanceCount()); // Announce with service names as specified in app arguments and runnable arguments final List<Cancellable> cancellables = new ArrayList<>(); for (String[] args : new String[][] {context.getApplicationArguments(), context.getArguments()}) { if (args.length > 0) { cancellables.add(context.announce(args[0], serverSocket.getLocalPort())); } } canceller = new Cancellable() { @Override public void cancel() { for (Cancellable c : cancellables) { c.cancel(); } } }; } catch (IOException e) { throw Throwables.propagate(e); } }
Cancellable cancellable = getContext().announce("discovered", 12345); completion.await(); cancellable.cancel();