示例#1
0
  // need to ask for objects...  start in order
  @Test
  public void testGetAllSegmentsFromPipeline() {
    Log.info(Log.FAC_TEST, "Starting testGetAllSegmentsFromPipeline");

    long received = 0;
    byte[] bytes = new byte[1024];

    try {
      istream = new CCNInputStream(testName, readHandle);
    } catch (IOException e1) {
      Log.warning(Log.FAC_TEST, "failed to open stream for pipeline test: " + e1.getMessage());
      Assert.fail();
    }

    while (!istream.eof()) {
      try {
        received += istream.read(bytes);
      } catch (IOException e) {
        Log.warning(Log.FAC_TEST, "failed to read segments: " + e.getMessage());
        Assert.fail();
      }
    }
    Log.info(Log.FAC_TEST, "read " + received + " from stream");
    Assert.assertTrue(received == bytesWritten);

    Log.info(Log.FAC_TEST, "Completed testGetAllSegmentsFromPipeline");
  }
示例#2
0
  // skip
  @Test
  public void testSkipWithPipeline() {
    Log.info(Log.FAC_TEST, "Starting testSkipWithPipeline");

    long received = 0;
    byte[] bytes = new byte[100];

    boolean skipDone = false;

    try {
      istream = new CCNInputStream(testName, readHandle);
    } catch (IOException e1) {
      Log.warning(Log.FAC_TEST, "Failed to get new stream: " + e1.getMessage());
      Assert.fail();
    }

    while (!istream.eof()) {
      try {
        Log.info(Log.FAC_TEST, "Read so far: " + received);
        if (received > 0 && received < 250 && !skipDone) {
          // want to skip some segments
          istream.skip(100);
          skipDone = true;
        }
        received += istream.read(bytes);
      } catch (IOException e) {
        Log.info(Log.FAC_TEST, "failed to read segments: " + e.getMessage());
        Assert.fail();
      }
    }
    Log.info(Log.FAC_TEST, "read " + received + " from stream");
    Assert.assertTrue(received == bytesWritten - 100);

    Log.info(Log.FAC_TEST, "Completed testSkipWithPipeline");
  }
示例#3
0
 private void checkData(ContentName name, byte[] check) throws IOException {
   CCNInputStream input = new CCNInputStream(name, getHandle);
   byte[] buffer = new byte[check.length];
   Assert.assertTrue(-1 != input.read(buffer));
   Assert.assertArrayEquals(buffer, check);
   input.close();
 }
示例#4
0
  @Test
  public void testGetFirstDigest() {
    Log.info(Log.FAC_TEST, "Starting testGetFirstDigest");

    long received = 0;
    byte[] bytes = new byte[1024];

    try {
      istream = new CCNInputStream(testName, readHandle);
    } catch (IOException e1) {
      Log.warning(Log.FAC_TEST, "failed to open stream for pipeline test: " + e1.getMessage());
      Assert.fail();
    }

    try {
      Assert.assertTrue(DataUtils.arrayEquals(firstDigest, istream.getFirstDigest()));
    } catch (IOException e3) {
      Log.warning(Log.FAC_TEST, "failed to get first digest for pipeline test:");
      Assert.fail();
    }
    try {
      istream.close();
    } catch (IOException e2) {
      Log.warning(Log.FAC_TEST, "failed to close stream for pipeline test: " + e2.getMessage());
      Assert.fail();
    }
    Log.info(Log.FAC_TEST, "start first segment digest " + DataUtils.printBytes(firstDigest));

    try {
      istream = new CCNInputStream(testName, readHandle);
    } catch (IOException e1) {
      Log.warning(Log.FAC_TEST, "failed to open stream for pipeline test: " + e1.getMessage());
      Assert.fail();
    }

    while (!istream.eof()) {
      try {
        received += istream.read(bytes);
      } catch (IOException e) {
        Log.warning(Log.FAC_TEST, "failed to read segments: " + e.getMessage());
        Assert.fail();
      }
    }
    Assert.assertTrue(received == bytesWritten);
    try {
      Assert.assertTrue(DataUtils.arrayEquals(firstDigest, istream.getFirstDigest()));
    } catch (IOException e) {
      Log.warning(Log.FAC_TEST, "failed to get first digest after reading in pipeline test:");
      Assert.fail();
    }
    Log.info(Log.FAC_TEST, "end first segment digest " + DataUtils.printBytes(firstDigest));

    Log.info(Log.FAC_TEST, "Completed testGetFirstDigest");
  }