Exemplo n.º 1
1
  @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);
  }
Exemplo n.º 2
0
  @Test
  public final void testHttpDataServer() throws Exception {
    Random rnd = new Random();
    FileWriter writer = new FileWriter(TEST_DATA + "/" + "testHttp");
    String watermark = "test_" + rnd.nextInt();
    writer.write(watermark + "\n");
    writer.flush();
    writer.close();

    DataRetriever ret = new DirectoryRetriever(TEST_DATA);
    HttpDataServer server = new HttpDataServer(NetUtils.createSocketAddr("127.0.0.1:0"), ret);
    server.start();

    InetSocketAddress addr = server.getBindAddress();
    URL url = new URL("http://127.0.0.1:" + addr.getPort() + "/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();
    server.stop();
  }