当前位置: 首页>>代码示例>>Java>>正文


Java Holder类代码示例

本文整理汇总了Java中org.apache.hadoop.hdfs.util.Holder的典型用法代码示例。如果您正苦于以下问题:Java Holder类的具体用法?Java Holder怎么用?Java Holder使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


Holder类属于org.apache.hadoop.hdfs.util包,在下文中一共展示了Holder类的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testReadURL

import org.apache.hadoop.hdfs.util.Holder; //导入依赖的package包/类
@Test
public void testReadURL() throws Exception {
  HttpURLConnection conn = mock(HttpURLConnection.class);
  doReturn(new ByteArrayInputStream(FAKE_LOG_DATA)).when(conn).getInputStream();
  doReturn(HttpURLConnection.HTTP_OK).when(conn).getResponseCode();
  doReturn(Integer.toString(FAKE_LOG_DATA.length)).when(conn).getHeaderField("Content-Length");

  URLConnectionFactory factory = mock(URLConnectionFactory.class);
  doReturn(conn).when(factory).openConnection(Mockito.<URL> any(),
      anyBoolean());

  URL url = new URL("http://localhost/fakeLog");
  EditLogInputStream elis = EditLogFileInputStream.fromUrl(factory, url,
      HdfsConstants.INVALID_TXID, HdfsConstants.INVALID_TXID, false);
  // Read the edit log and verify that we got all of the data.
  EnumMap<FSEditLogOpCodes, Holder<Integer>> counts = FSImageTestUtil
      .countEditLogOpTypes(elis);
  assertThat(counts.get(FSEditLogOpCodes.OP_ADD).held, is(1));
  assertThat(counts.get(FSEditLogOpCodes.OP_SET_GENSTAMP_V1).held, is(1));
  assertThat(counts.get(FSEditLogOpCodes.OP_CLOSE).held, is(1));

  // Check that length header was picked up.
  assertEquals(FAKE_LOG_DATA.length, elis.length());
  elis.close();
}
 
开发者ID:naver,项目名称:hadoop,代码行数:26,代码来源:TestEditLogFileInputStream.java

示例2: countEditLogOpTypes

import org.apache.hadoop.hdfs.util.Holder; //导入依赖的package包/类
/**
 * @see #countEditLogOpTypes(File)
 */
public static EnumMap<FSEditLogOpCodes, Holder<Integer>> countEditLogOpTypes(
    EditLogInputStream elis) throws IOException {
  EnumMap<FSEditLogOpCodes, Holder<Integer>> opCounts =
      new EnumMap<FSEditLogOpCodes, Holder<Integer>>(FSEditLogOpCodes.class);
  
  FSEditLogOp op;
  while ((op = elis.readOp()) != null) {
    Holder<Integer> i = opCounts.get(op.opCode);
    if (i == null) {
      i = new Holder<Integer>(0);
      opCounts.put(op.opCode, i);
    }
    i.held++;
  }
  return opCounts;
}
 
开发者ID:naver,项目名称:hadoop,代码行数:20,代码来源:FSImageTestUtil.java

示例3: writeSegmentUntilCrash

import org.apache.hadoop.hdfs.util.Holder; //导入依赖的package包/类
private long writeSegmentUntilCrash(MiniJournalCluster cluster,
    QuorumJournalManager qjm, long txid, int numTxns, Holder<Throwable> thrown) {
  
  long firstTxId = txid;
  long lastAcked = txid - 1;
  try {
    EditLogOutputStream stm = qjm.startLogSegment(txid,
        NameNodeLayoutVersion.CURRENT_LAYOUT_VERSION);
    
    for (int i = 0; i < numTxns; i++) {
      QJMTestUtil.writeTxns(stm, txid++, 1);
      lastAcked++;
    }
    
    stm.close();
    qjm.finalizeLogSegment(firstTxId, lastAcked);
  } catch (Throwable t) {
    thrown.held = t;
  }
  return lastAcked;
}
 
开发者ID:naver,项目名称:hadoop,代码行数:22,代码来源:TestQJMWithFaults.java

示例4: testReadURL

import org.apache.hadoop.hdfs.util.Holder; //导入依赖的package包/类
@Test
public void testReadURL() throws Exception {
  HttpURLConnection conn = mock(HttpURLConnection.class);
  doReturn(new ByteArrayInputStream(FAKE_LOG_DATA)).when(conn).getInputStream();
  doReturn(HttpURLConnection.HTTP_OK).when(conn).getResponseCode();
  doReturn(Integer.toString(FAKE_LOG_DATA.length)).when(conn).getHeaderField("Content-Length");

  URLConnectionFactory factory = mock(URLConnectionFactory.class);
  doReturn(conn).when(factory).openConnection(Mockito.<URL> any(),
      anyBoolean());

  URL url = new URL("http://localhost/fakeLog");
  EditLogInputStream elis = EditLogFileInputStream.fromUrl(factory, url,
      HdfsServerConstants.INVALID_TXID, HdfsServerConstants.INVALID_TXID, false);
  // Read the edit log and verify that we got all of the data.
  EnumMap<FSEditLogOpCodes, Holder<Integer>> counts = FSImageTestUtil
      .countEditLogOpTypes(elis);
  assertThat(counts.get(FSEditLogOpCodes.OP_ADD).held, is(1));
  assertThat(counts.get(FSEditLogOpCodes.OP_SET_GENSTAMP_V1).held, is(1));
  assertThat(counts.get(FSEditLogOpCodes.OP_CLOSE).held, is(1));

  // Check that length header was picked up.
  assertEquals(FAKE_LOG_DATA.length, elis.length());
  elis.close();
}
 
开发者ID:aliyun-beta,项目名称:aliyun-oss-hadoop-fs,代码行数:26,代码来源:TestEditLogFileInputStream.java

示例5: writeSegmentUntilCrash

import org.apache.hadoop.hdfs.util.Holder; //导入依赖的package包/类
private long writeSegmentUntilCrash(MiniJournalCluster cluster,
    QuorumJournalManager qjm, long txid, int numTxns, Holder<Throwable> thrown) {
  
  long firstTxId = txid;
  long lastAcked = txid - 1;
  try {
    EditLogOutputStream stm = qjm.startLogSegment(txid);
    
    for (int i = 0; i < numTxns; i++) {
      QJMTestUtil.writeTxns(stm, txid++, 1);
      lastAcked++;
    }
    
    stm.close();
    qjm.finalizeLogSegment(firstTxId, lastAcked);
  } catch (Throwable t) {
    thrown.held = t;
  }
  return lastAcked;
}
 
开发者ID:rhli,项目名称:hadoop-EAR,代码行数:21,代码来源:TestQJMWithFaults.java

示例6: testReadURL

import org.apache.hadoop.hdfs.util.Holder; //导入依赖的package包/类
@Test
public void testReadURL() throws Exception {
  // Start a simple web server which hosts the log data.
  HttpServer server = new HttpServer("test", "0.0.0.0", 0, true);
  server.start();
  try {
    server.addServlet("fakeLog", "/fakeLog", FakeLogServlet.class);
    URL url = new URL("http://localhost:" + server.getPort() + "/fakeLog");
    EditLogInputStream elis = EditLogFileInputStream.fromUrl(
        url, HdfsConstants.INVALID_TXID, HdfsConstants.INVALID_TXID,
        false);
    // Read the edit log and verify that we got all of the data.
    EnumMap<FSEditLogOpCodes, Holder<Integer>> counts =
        FSImageTestUtil.countEditLogOpTypes(elis);
    assertThat(counts.get(FSEditLogOpCodes.OP_ADD).held, is(1));
    assertThat(counts.get(FSEditLogOpCodes.OP_SET_GENSTAMP_V1).held, is(1));
    assertThat(counts.get(FSEditLogOpCodes.OP_CLOSE).held, is(1));

    // Check that length header was picked up.
    assertEquals(FAKE_LOG_DATA.length, elis.length());
    elis.close();
  } finally {
    server.stop();
  }
}
 
开发者ID:ict-carch,项目名称:hadoop-plus,代码行数:26,代码来源:TestEditLogFileInputStream.java

示例7: dumpOpCounts

import org.apache.hadoop.hdfs.util.Holder; //导入依赖的package包/类
private static void dumpOpCounts(
    EnumMap<FSEditLogOpCodes, Holder<Integer>> opCounts) {
  StringBuilder sb = new StringBuilder();
  sb.append("Summary of operations loaded from edit log:\n  ");
  Joiner.on("\n  ").withKeyValueSeparator("=").appendTo(sb, opCounts);
  FSImage.LOG.debug(sb.toString());
}
 
开发者ID:naver,项目名称:hadoop,代码行数:8,代码来源:FSEditLogLoader.java

示例8: incrOpCount

import org.apache.hadoop.hdfs.util.Holder; //导入依赖的package包/类
private void incrOpCount(FSEditLogOpCodes opCode,
    EnumMap<FSEditLogOpCodes, Holder<Integer>> opCounts, Step step,
    Counter counter) {
  Holder<Integer> holder = opCounts.get(opCode);
  if (holder == null) {
    holder = new Holder<Integer>(1);
    opCounts.put(opCode, holder);
  } else {
    holder.held++;
  }
  counter.increment();
}
 
开发者ID:naver,项目名称:hadoop,代码行数:13,代码来源:FSEditLogLoader.java


注:本文中的org.apache.hadoop.hdfs.util.Holder类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。