private ShellMsg mockMsg() { ShellMsg shellMsg = mock(ShellMsg.class); when(shellMsg.getMsg()).thenReturn("msg"); when(shellMsg.getLogLevel()).thenReturn(ShellLogLevel.INFO); return shellMsg; }
public ShellMsg readShellMsg() throws IOException, NoOutputException { JSONObject msg = (JSONObject) readMessage(); ShellMsg shellMsg = new ShellMsg(); shellMsg.setCommand(command); shellMsg.setId(id); shellMsg.setMsg(log); shellMsg.setStream(stream); shellMsg.setTask((Long) taskObj); } else { shellMsg.setTask(0); shellMsg.setNeedTaskIds(true); } else { shellMsg.setNeedTaskIds(false); shellMsg.setTuple((List) msg.get("tuple")); shellMsg.addAnchor((String) o); shellMsg.setMetricName(metricName); shellMsg.setMetricParams(paramsObj); if (logLevelObj != null && logLevelObj instanceof Long) { long logLevel = (Long) logLevelObj;
String command = shellMsg.getCommand(); if (command == null) { throw new IllegalArgumentException("Command not found in spout message: " + shellMsg); _logHandler.log(shellMsg); } else if (command.equals("error")) { handleError(shellMsg.getMsg()); } else if (command.equals("emit")) { String stream = shellMsg.getStream(); Long task = shellMsg.getTask(); List<Object> tuple = shellMsg.getTuple(); Object messageId = shellMsg.getId(); if (task == 0) { List<Integer> outtasks = _collector.emit(stream, tuple, messageId); if (shellMsg.areTaskIdsNeeded()) { _process.writeTaskIds(outtasks);
private void handleEmit(ShellMsg shellMsg) throws InterruptedException { List<Tuple> anchors = new ArrayList<>(); List<String> recvAnchors = shellMsg.getAnchors(); if (recvAnchors != null) { for (String anchor : recvAnchors) { Tuple t = _inputs.get(anchor); if (t == null) { throw new RuntimeException("Anchored onto " + anchor + " after ack/fail"); } anchors.add(t); } } if (shellMsg.getTask() == 0) { List<Integer> outtasks = _collector.emit(shellMsg.getStream(), anchors, shellMsg.getTuple()); if (shellMsg.areTaskIdsNeeded()) { _pendingWrites.putTaskIds(outtasks); } } else { _collector.emitDirect((int) shellMsg.getTask(), shellMsg.getStream(), anchors, shellMsg.getTuple()); } }
ShellMsg shellMsg = _process.readShellMsg(); String command = shellMsg.getCommand(); if (command == null) { throw new IllegalArgumentException("Command not found in bolt message: " + shellMsg); handleAck(shellMsg.getId()); break; case "fail": handleFail(shellMsg.getId()); break; case "error": handleError(shellMsg.getMsg()); break; case "log":
private void handleMetrics(ShellMsg shellMsg) { //get metric name String name = shellMsg.getMetricName(); if (name.isEmpty()) { throw new RuntimeException("Receive Metrics name is empty"); } //get metric by name IMetric iMetric = _context.getRegisteredMetricByName(name); if (iMetric == null) { throw new RuntimeException("Could not find metric by name[" + name + "] "); } if (!(iMetric instanceof IShellMetric)) { throw new RuntimeException("Metric[" + name + "] is not IShellMetric, can not call by RPC"); } IShellMetric iShellMetric = (IShellMetric) iMetric; //call updateMetricFromRPC with params Object paramsObj = shellMsg.getMetricParams(); try { iShellMetric.updateMetricFromRPC(paramsObj); } catch (RuntimeException re) { throw re; } catch (Exception e) { throw new RuntimeException(e); } }
/** * Calling setUpContext is optional. */ @Test public void setUpContext_optional() { ShellMsg msg = mockMsg(); logHandler.log(msg); verify(msg).getMsg(); }
private void handleEmit(ShellMsg shellMsg) throws InterruptedException { List<Tuple> anchors = new ArrayList<>(); List<String> recvAnchors = shellMsg.getAnchors(); if (recvAnchors != null) { for (String anchor : recvAnchors) { Tuple t = _inputs.get(anchor); if (t == null) { throw new RuntimeException("Anchored onto " + anchor + " after ack/fail"); } anchors.add(t); } } if(shellMsg.getTask() == 0) { List<Integer> outtasks = _collector.emit(shellMsg.getStream(), anchors, shellMsg.getTuple()); if (shellMsg.areTaskIdsNeeded()) { _pendingWrites.putTaskIds(outtasks); } } else { _collector.emitDirect((int) shellMsg.getTask(), shellMsg.getStream(), anchors, shellMsg.getTuple()); } }
ShellMsg shellMsg = _process.readShellMsg(); String command = shellMsg.getCommand(); if (command == null) { throw new IllegalArgumentException("Command not found in bolt message: " + shellMsg); handleAck(shellMsg.getId()); break; case "fail": handleFail(shellMsg.getId()); break; case "error": handleError(shellMsg.getMsg()); break; case "log":
private void handleMetrics(ShellMsg shellMsg) { //get metric name String name = shellMsg.getMetricName(); if (name.isEmpty()) { throw new RuntimeException("Receive Metrics name is empty"); } //get metric by name IMetric iMetric = _context.getRegisteredMetricByName(name); if (iMetric == null) { throw new RuntimeException("Could not find metric by name[" + name + "] "); } if (!(iMetric instanceof IShellMetric)) { throw new RuntimeException("Metric[" + name + "] is not IShellMetric, can not call by RPC"); } IShellMetric iShellMetric = (IShellMetric) iMetric; //call updateMetricFromRPC with params Object paramsObj = shellMsg.getMetricParams(); try { iShellMetric.updateMetricFromRPC(paramsObj); } catch (RuntimeException re) { throw re; } catch (Exception e) { throw new RuntimeException(e); } }
/** * 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(); }
public ShellMsg readShellMsg() throws IOException, NoOutputException { JSONObject msg = (JSONObject) readMessage(); ShellMsg shellMsg = new ShellMsg(); shellMsg.setCommand(command); shellMsg.setId(id); shellMsg.setMsg(log); shellMsg.setStream(stream); shellMsg.setTask((Long) taskObj); } else { shellMsg.setTask(0); shellMsg.setNeedTaskIds(true); } else { shellMsg.setNeedTaskIds(false); shellMsg.setTuple((List) msg.get("tuple")); shellMsg.addAnchor((String) o); shellMsg.setMetricName(metricName); shellMsg.setMetricParams(paramsObj); if (logLevelObj != null && logLevelObj instanceof Long) { long logLevel = (Long)logLevelObj;
String command = shellMsg.getCommand(); if (command == null) { throw new IllegalArgumentException("Command not found in spout message: " + shellMsg); _logHandler.log(shellMsg); } else if (command.equals("error")) { handleError(shellMsg.getMsg()); } else if (command.equals("emit")) { String stream = shellMsg.getStream(); Long task = shellMsg.getTask(); List<Object> tuple = shellMsg.getTuple(); Object messageId = shellMsg.getId(); if (task == 0) { List<Integer> outtasks = _collector.emit(stream, tuple, messageId); if (shellMsg.areTaskIdsNeeded()) { _process.writeTaskIds(outtasks);
throw new IllegalArgumentException("shellMsg is required"); String msg = shellMsg.getMsg(); if (this.log == null) { this.log = getLogger(null); msg = "ShellLog " + process.getProcessInfoString() + " " + msg; ShellMsg.ShellLogLevel logLevel = shellMsg.getLogLevel();
private void handleMetrics(ShellMsg shellMsg) { //get metric name String name = shellMsg.getMetricName(); if (name.isEmpty()) { throw new RuntimeException("Receive Metrics name is empty"); } //get metric by name IMetric iMetric = _context.getRegisteredMetricByName(name); if (iMetric == null) { throw new RuntimeException("Could not find metric by name["+name+"] "); } if ( !(iMetric instanceof IShellMetric)) { throw new RuntimeException("Metric["+name+"] is not IShellMetric, can not call by RPC"); } IShellMetric iShellMetric = (IShellMetric)iMetric; //call updateMetricFromRPC with params Object paramsObj = shellMsg.getMetricParams(); try { iShellMetric.updateMetricFromRPC(paramsObj); } catch (RuntimeException re) { throw re; } catch (Exception e) { throw new RuntimeException(e); } }
/** * 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(); } }
throw new IllegalArgumentException("shellMsg is required"); String msg = shellMsg.getMsg(); if (this.log == null) { this.log = getLogger(null); msg = "ShellLog " + process.getProcessInfoString() + " " + msg; ShellMsg.ShellLogLevel logLevel = shellMsg.getLogLevel();
private void handleMetrics(ShellMsg shellMsg) { //get metric name String name = shellMsg.getMetricName(); if (name.isEmpty()) { throw new RuntimeException("Receive Metrics name is empty"); } //get metric by name IMetric iMetric = _context.getRegisteredMetricByName(name); if (iMetric == null) { throw new RuntimeException("Could not find metric by name["+name+"] "); } if ( !(iMetric instanceof IShellMetric)) { throw new RuntimeException("Metric["+name+"] is not IShellMetric, can not call by RPC"); } IShellMetric iShellMetric = (IShellMetric)iMetric; //call updateMetricFromRPC with params Object paramsObj = shellMsg.getMetricParams(); try { iShellMetric.updateMetricFromRPC(paramsObj); } catch (RuntimeException re) { throw re; } catch (Exception e) { throw new RuntimeException(e); } }
/** * 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(); }