/** Basic upload through the channel. */
  @Test
  public void testBasic() throws Exception {
    long txid = 101;
    int iterations = 10;

    HttpImageUploadChannel channel =
        new HttpImageUploadChannel(httpAddress, journalId, FAKE_NSINFO, txid, 0, 100);
    channel.start();

    ByteArrayOutputStream bos = genBos();
    for (int i = 0; i < iterations; i++) {
      channel.send(bos);
    }
    channel.close();

    // validate

    // the file should exist
    File uploaded = journal.getImageStorage().getCheckpointImageFile(txid);
    assertTrue(uploaded.exists());
    assertEquals(iterations * randomBytes.length, uploaded.length());

    // assert contents of the uploaded file
    InputStream is = new FileInputStream(uploaded);
    byte[] contents = new byte[randomBytes.length];

    for (int i = 0; i < iterations; i++) {
      is.read(contents);
      assertTrue(Arrays.equals(randomBytes, contents));
    }
    is.close();
  }
  @Test
  public void testMaxBuffer() throws Exception {
    long txid = 101;
    // set timeout to 5 seconds
    HttpImageUploadChannel.setTimeoutForTesting(5);
    // setting -1 will cause the first send operation to fail
    HttpImageUploadChannel channel =
        new HttpImageUploadChannel(httpAddress, journalId, FAKE_NSINFO, txid, 0, -1);
    channel.start();

    ByteArrayOutputStream bos = genBos();
    channel.send(bos);
    assertTrue(channel.isDisabled());
  }