public void setLogLevel(int logLevel) { this.logLevel = ShellLogLevel.fromInt(logLevel); }
public void writeTaskIds(List<Integer> taskIds) throws IOException { writeMessage(taskIds); }
public void writeBoltMsg(BoltMsg boltMsg) throws IOException { JSONObject obj = new JSONObject(); obj.put("id", boltMsg.getId()); obj.put("comp", boltMsg.getComp()); obj.put("stream", boltMsg.getStream()); obj.put("task", boltMsg.getTask()); obj.put("tuple", boltMsg.getTuple()); writeMessage(obj); }
private void sendSyncCommand(String command, Object msgId) { if (_exception != null) { throw _exception; } if (_spoutMsg == null) { _spoutMsg = new SpoutMsg(); } _spoutMsg.setCommand(command); _spoutMsg.setId(msgId); querySubprocess(); }
public void writeSpoutMsg(SpoutMsg msg) throws IOException { JSONObject obj = new JSONObject(); obj.put("command", msg.getCommand()); obj.put("id", msg.getId()); writeMessage(obj); }
private ShellMsg mockMsg() { ShellMsg shellMsg = mock(ShellMsg.class); when(shellMsg.getMsg()).thenReturn("msg"); when(shellMsg.getLogLevel()).thenReturn(ShellLogLevel.INFO); return shellMsg; }
/** * Calling setUpContext is optional. */ @Test public void setUpContext_optional() { ShellMsg msg = mockMsg(); logHandler.log(msg); verify(msg).getMsg(); }
public Number connect(Map<String, Object> conf, TopologyContext context) throws IOException, NoOutputException { JSONObject setupInfo = new JSONObject(); setupInfo.put("pidDir", context.getPIDDir()); setupInfo.put("conf", conf); setupInfo.put("context", context); writeMessage(setupInfo); Number pid = (Number) ((JSONObject) readMessage()).get("pid"); return pid; }
@Test public void testPollTaskIdsFirst() throws InterruptedException { ShellBoltMessageQueue queue = new ShellBoltMessageQueue(); // put bolt message first, then put task ids queue.putBoltMsg(new BoltMsg()); ArrayList<Integer> taskIds = Lists.newArrayList(1, 2, 3); queue.putTaskIds(taskIds); Object msg = queue.poll(10, TimeUnit.SECONDS); // task ids should be pulled first assertTrue(msg instanceof List<?>); assertEquals(msg, taskIds); }
public void writeBoltMsg(BoltMsg msg) throws IOException { serializer.writeBoltMsg(msg); // Log any info sent on the error stream logErrorStream(); }
public void writeSpoutMsg(SpoutMsg msg) throws IOException { serializer.writeSpoutMsg(msg); // Log any info sent on the error stream logErrorStream(); }
public void writeTaskIds(List<Integer> taskIds) throws IOException { serializer.writeTaskIds(taskIds); // Log any info sent on the error stream logErrorStream(); }
private void writeMessage(Object msg) throws IOException { writeString(JSONValue.toJSONString(msg)); }
private Object readMessage() throws IOException, NoOutputException { try { return JSONValue.parseWithException(readString()); } catch (ParseException e) { throw new IOException(e); } }
public ShellMsg readShellMsg() throws IOException { try { return serializer.readShellMsg(); } catch (NoOutputException e) { throw new RuntimeException(e + getErrorsString() + "\n"); } }
private BoltMsg createBoltMessage(Tuple input, String genId) { BoltMsg boltMsg = new BoltMsg(); boltMsg.setId(genId); boltMsg.setComp(input.getSourceComponent()); boltMsg.setStream(input.getSourceStreamId()); boltMsg.setTask(input.getSourceTask()); boltMsg.setTuple(input.getValues()); return boltMsg; }
/** * It's fine to pass only null arguments to setUpContext. */ @Test public void setUpContext_allNull() { ShellMsg msg = mockMsg(); logHandler.setUpContext(null, null, null); logHandler.log(msg); verify(msg).getMsg(); }
/** * A null {@link ShellProcess} will not throw an exception. */ @Test public void handleLog_nullProcess() { ShellMsg msg = mockMsg(); ShellProcess process = mockProcess(); logHandler.setUpContext(DefaultShellLogHandlerTest.class, process, null); logHandler.log(msg); verify(msg).getMsg(); }
/** * If both {@link ShellMsg} and {@link ShellProcess} are provided, both * will be used to build the log message. */ @Test public void handleLog_valid() { ShellMsg msg = mockMsg(); ShellProcess process = mockProcess(); logHandler.setUpContext(DefaultShellLogHandlerTest.class, process, null); logHandler.log(msg); verify(msg).getMsg(); verify(process).getProcessInfoString(); } }