Java Code Examples for org.apache.hadoop.hdfs.DFSTestUtil#urlGetBytes()

The following examples show how to use org.apache.hadoop.hdfs.DFSTestUtil#urlGetBytes() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TestJournalNode.java    From hadoop with Apache License 2.0 4 votes vote down vote up
@Test(timeout=100000)
public void testHttpServer() throws Exception {
  String urlRoot = jn.getHttpServerURI();
  
  // Check default servlets.
  String pageContents = DFSTestUtil.urlGet(new URL(urlRoot + "/jmx"));
  assertTrue("Bad contents: " + pageContents,
      pageContents.contains(
          "Hadoop:service=JournalNode,name=JvmMetrics"));

  // Create some edits on server side
  byte[] EDITS_DATA = QJMTestUtil.createTxnData(1, 3);
  IPCLoggerChannel ch = new IPCLoggerChannel(
      conf, FAKE_NSINFO, journalId, jn.getBoundIpcAddress());
  ch.newEpoch(1).get();
  ch.setEpoch(1);
  ch.startLogSegment(1, NameNodeLayoutVersion.CURRENT_LAYOUT_VERSION).get();
  ch.sendEdits(1L, 1, 3, EDITS_DATA).get();
  ch.finalizeLogSegment(1, 3).get();

  // Attempt to retrieve via HTTP, ensure we get the data back
  // including the header we expected
  byte[] retrievedViaHttp = DFSTestUtil.urlGetBytes(new URL(urlRoot +
      "/getJournal?segmentTxId=1&jid=" + journalId));
  byte[] expected = Bytes.concat(
          Ints.toByteArray(HdfsConstants.NAMENODE_LAYOUT_VERSION),
          (new byte[] { 0, 0, 0, 0 }), // layout flags section
          EDITS_DATA);

  assertArrayEquals(expected, retrievedViaHttp);
  
  // Attempt to fetch a non-existent file, check that we get an
  // error status code
  URL badUrl = new URL(urlRoot + "/getJournal?segmentTxId=12345&jid=" + journalId);
  HttpURLConnection connection = (HttpURLConnection)badUrl.openConnection();
  try {
    assertEquals(404, connection.getResponseCode());
  } finally {
    connection.disconnect();
  }
}
 
Example 2
Source File: TestJournalNode.java    From big-c with Apache License 2.0 4 votes vote down vote up
@Test(timeout=100000)
public void testHttpServer() throws Exception {
  String urlRoot = jn.getHttpServerURI();
  
  // Check default servlets.
  String pageContents = DFSTestUtil.urlGet(new URL(urlRoot + "/jmx"));
  assertTrue("Bad contents: " + pageContents,
      pageContents.contains(
          "Hadoop:service=JournalNode,name=JvmMetrics"));

  // Create some edits on server side
  byte[] EDITS_DATA = QJMTestUtil.createTxnData(1, 3);
  IPCLoggerChannel ch = new IPCLoggerChannel(
      conf, FAKE_NSINFO, journalId, jn.getBoundIpcAddress());
  ch.newEpoch(1).get();
  ch.setEpoch(1);
  ch.startLogSegment(1, NameNodeLayoutVersion.CURRENT_LAYOUT_VERSION).get();
  ch.sendEdits(1L, 1, 3, EDITS_DATA).get();
  ch.finalizeLogSegment(1, 3).get();

  // Attempt to retrieve via HTTP, ensure we get the data back
  // including the header we expected
  byte[] retrievedViaHttp = DFSTestUtil.urlGetBytes(new URL(urlRoot +
      "/getJournal?segmentTxId=1&jid=" + journalId));
  byte[] expected = Bytes.concat(
          Ints.toByteArray(HdfsConstants.NAMENODE_LAYOUT_VERSION),
          (new byte[] { 0, 0, 0, 0 }), // layout flags section
          EDITS_DATA);

  assertArrayEquals(expected, retrievedViaHttp);
  
  // Attempt to fetch a non-existent file, check that we get an
  // error status code
  URL badUrl = new URL(urlRoot + "/getJournal?segmentTxId=12345&jid=" + journalId);
  HttpURLConnection connection = (HttpURLConnection)badUrl.openConnection();
  try {
    assertEquals(404, connection.getResponseCode());
  } finally {
    connection.disconnect();
  }
}