EmptyDatastoreVerifierProcess implements Process { @Override public void run(PortBindings portBindings, Configuration conf, Map<String, String> parameters) throws Exception { if (!portBindings.getInput().containsKey(INPUT_PORT_NAME)) { throw new InvalidParameterException("missing input port!"); } try (CloseableIterator<?> closeableIt = getIterator(conf, portBindings.getInput().get(INPUT_PORT_NAME))) { File file = new File(System.getProperty(OOZIE_ACTION_OUTPUT_FILENAME)); Properties props = new Properties(); props.setProperty(OUTPUT_PROPERTY_IS_EMPTY, Boolean.toString(!closeableIt.hasNext())); try (OutputStream os = new FileOutputStream(file)) { props.store(os, ""); } } } EmptyDatastoreVerifierProcess(); @Override Map<String, PortType> getInputPorts(); @Override Map<String, PortType> getOutputPorts(); @Override void run(PortBindings portBindings, Configuration conf, Map<String, String> parameters); static final String INPUT_PORT_NAME; static final String DEFAULT_ENCODING; static final String OUTPUT_PROPERTY_IS_EMPTY; }
@Test(expected=InvalidParameterException.class) public void testVerifyEmptyDatastoreWithoutInput() throws Exception { process.run(new PortBindings(Collections.emptyMap(), Collections.emptyMap()), conf, parameters); }
@Test public void testVerifyEmptyDatastore() throws Exception { Map<String, Path> input = new HashMap<>(); input.put(EmptyDatastoreVerifierProcess.INPUT_PORT_NAME, new Path("/irrelevant/location/as/it/will/be/mocked")); PortBindings portBindings = new PortBindings(input, Collections.emptyMap()); doReturn(false).when(iterator).hasNext(); process.run(portBindings, conf, parameters); assertTrue(verifyAndGetResult()); }
@Test public void testVerifyNonEmptyDatastore() throws Exception { Map<String, Path> input = new HashMap<>(); input.put(EmptyDatastoreVerifierProcess.INPUT_PORT_NAME, new Path("/irrelevant/location/as/it/will/be/mocked")); PortBindings portBindings = new PortBindings(input, Collections.emptyMap()); doReturn(true).when(iterator).hasNext(); process.run(portBindings, conf, parameters); assertFalse(verifyAndGetResult()); }