@Test(expected = FileNotFoundException.class) public final void testNoSuchFile() throws Exception { QueryIdFactory.reset(); SubQueryId schid = QueryIdFactory.newSubQueryId(QueryIdFactory.newQueryId()); QueryUnitId qid1 = QueryIdFactory.newQueryUnitId(schid); QueryUnitId qid2 = QueryIdFactory.newQueryUnitId(schid); File qid1Dir = new File(TEST_DATA + "/" + qid1.toString() + "/out"); qid1Dir.mkdirs(); File qid2Dir = new File(TEST_DATA + "/" + qid2.toString() + "/out"); qid2Dir.mkdirs(); Random rnd = new Random(); FileWriter writer = new FileWriter(qid1Dir + "/" + "testHttp"); String watermark1 = "test_" + rnd.nextInt(); writer.write(watermark1); writer.flush(); writer.close(); writer = new FileWriter(qid2Dir + "/" + "testHttp"); String watermark2 = "test_" + rnd.nextInt(); writer.write(watermark2); writer.flush(); writer.close(); InterDataRetriever ret = new InterDataRetriever(); HttpDataServer server = new HttpDataServer(NetUtils.createSocketAddr("127.0.0.1:0"), ret); server.start(); ret.register(qid1, qid1Dir.getPath()); InetSocketAddress addr = server.getBindAddress(); assertDataRetrival(qid1, addr.getPort(), watermark1); ret.unregister(qid1); assertDataRetrival(qid1, addr.getPort(), watermark1); }
private static void assertDataRetrival(QueryUnitId id, int port, String watermark) throws IOException { URL url = new URL("http://127.0.0.1:" + port + "/?qid=" + id.toString() + "&fn=testHttp"); BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream())); String line = null; boolean found = false; while ((line = in.readLine()) != null) { System.out.println(line); if (line.equals(watermark)) found = true; } assertTrue(found); in.close(); }