@Override public void execute(Tuple tuple) { processorBolt.execute(tuple); }
protected void parse(String url, byte[] content, Metadata metadata) throws IOException { Tuple tuple = mock(Tuple.class); when(tuple.getBinaryByField("content")).thenReturn(content); when(tuple.getStringByField("url")).thenReturn(url); when(tuple.getValueByField("metadata")).thenReturn(metadata); bolt.execute(tuple); }
protected void parse(String url, String filename, Metadata metadata) throws IOException { byte[] content = readContent(filename); Tuple tuple = mock(Tuple.class); when(tuple.getBinaryByField("content")).thenReturn(content); when(tuple.getStringByField("url")).thenReturn(url); when(tuple.getValueByField("metadata")).thenReturn(metadata); bolt.execute(tuple); }
@Test public void testDodgyURL() throws IOException { TestOutputCollector output = new TestOutputCollector(); Map config = new HashMap(); config.put("http.agent.name", "this is only a test"); bolt.prepare(config, TestUtil.getMockedTopologyContext(), new OutputCollector(output)); Tuple tuple = mock(Tuple.class); when(tuple.getSourceComponent()).thenReturn("source"); when(tuple.getStringByField("url")).thenReturn("ahahaha"); when(tuple.getValueByField("metadata")).thenReturn(null); bolt.execute(tuple); boolean acked = output.getAckedTuples().contains(tuple); boolean failed = output.getAckedTuples().contains(tuple); // should be acked or failed Assert.assertEquals(true, acked || failed); List<List<Object>> statusTuples = output .getEmitted(Constants.StatusStreamName); // we should get one tuple on the status stream // to notify that the URL is an error Assert.assertEquals(1, statusTuples.size()); }
"http://localhost:" + port + "/"); when(tuple.getValueByField("metadata")).thenReturn(null); bolt.execute(tuple);