Java Code Examples for org.apache.hadoop.test.GenericTestUtils#getRandomizedTestDir()

The following examples show how to use org.apache.hadoop.test.GenericTestUtils#getRandomizedTestDir() . 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: TestKeyValueContainerMarkUnhealthy.java    From hadoop-ozone with Apache License 2.0 6 votes vote down vote up
@Before
public void setUp() throws Exception {
  conf = new OzoneConfiguration();
  datanodeId = UUID.randomUUID();
  HddsVolume hddsVolume = new HddsVolume.Builder(folder.getRoot()
      .getAbsolutePath()).conf(conf).datanodeUuid(datanodeId
      .toString()).build();

  volumeSet = mock(MutableVolumeSet.class);
  volumeChoosingPolicy = mock(RoundRobinVolumeChoosingPolicy.class);
  Mockito.when(volumeChoosingPolicy.chooseVolume(anyList(), anyLong()))
      .thenReturn(hddsVolume);

  keyValueContainerData = new KeyValueContainerData(1L,
      layout,
      (long) StorageUnit.GB.toBytes(5), UUID.randomUUID().toString(),
      datanodeId.toString());
  final File metaDir = GenericTestUtils.getRandomizedTestDir();
  metaDir.mkdirs();
  keyValueContainerData.setMetadataPath(metaDir.getPath());


  keyValueContainer = new KeyValueContainer(
      keyValueContainerData, conf);
}
 
Example 2
Source File: TestVolumeSet.java    From hadoop-ozone with Apache License 2.0 6 votes vote down vote up
@Test
public void testFailVolumes() throws  Exception{
  MutableVolumeSet volSet = null;
  File readOnlyVolumePath = new File(baseDir);
  //Set to readonly, so that this volume will be failed
  readOnlyVolumePath.setReadOnly();
  File volumePath = GenericTestUtils.getRandomizedTestDir();
  OzoneConfiguration ozoneConfig = new OzoneConfiguration();
  ozoneConfig.set(HDDS_DATANODE_DIR_KEY, readOnlyVolumePath.getAbsolutePath()
      + "," + volumePath.getAbsolutePath());
  volSet = new MutableVolumeSet(UUID.randomUUID().toString(), ozoneConfig);
  assertEquals(1, volSet.getFailedVolumesList().size());
  assertEquals(readOnlyVolumePath, volSet.getFailedVolumesList().get(0)
      .getHddsRootDir());

  //Set back to writable
  try {
    readOnlyVolumePath.setWritable(true);
    volSet.shutdown();
  } finally {
    FileUtil.fullyDelete(volumePath);
  }

}
 
Example 3
Source File: TestSCMBlockProtocolServer.java    From hadoop-ozone with Apache License 2.0 6 votes vote down vote up
@Before
public void setUp() throws Exception {
  config = new OzoneConfiguration();
  File dir = GenericTestUtils.getRandomizedTestDir();
  config.set(HddsConfigKeys.OZONE_METADATA_DIRS, dir.toString());
  SCMConfigurator configurator = new SCMConfigurator();
  scm = TestUtils.getScm(config, configurator);
  scm.start();
  scm.exitSafeMode();
  // add nodes to scm node manager
  nodeManager = scm.getScmNodeManager();
  for (int i = 0; i < nodeCount; i++) {
    nodeManager.register(randomDatanodeDetails(), null, null);

  }
  server = scm.getBlockProtocolServer();
  service = new ScmBlockLocationProtocolServerSideTranslatorPB(server,
      Mockito.mock(ProtocolMessageMetrics.class));
}
 
Example 4
Source File: TestOzoneNativeAuthorizer.java    From hadoop-ozone with Apache License 2.0 6 votes vote down vote up
@BeforeClass
public static void setup() throws Exception {
  ozConfig = new OzoneConfiguration();
  ozConfig.set(OZONE_ACL_AUTHORIZER_CLASS,
      OZONE_ACL_AUTHORIZER_CLASS_NATIVE);
  File dir = GenericTestUtils.getRandomizedTestDir();
  ozConfig.set(OZONE_METADATA_DIRS, dir.toString());
  ozConfig.set(OZONE_ADMINISTRATORS, "om");

  metadataManager = new OmMetadataManagerImpl(ozConfig);
  volumeManager = new VolumeManagerImpl(metadataManager, ozConfig);
  bucketManager = new BucketManagerImpl(metadataManager);
  prefixManager = new PrefixManagerImpl(metadataManager, false);

  keyManager = new KeyManagerImpl(mock(ScmBlockLocationProtocol.class),
      metadataManager, ozConfig, "om1", null);

  nativeAuthorizer = new OzoneNativeAuthorizer(volumeManager, bucketManager,
      keyManager, prefixManager,
      Collections.singletonList("om"));
  adminUgi = UserGroupInformation.createUserForTesting("om",
      new String[]{"ozone"});
  testUgi = UserGroupInformation.createUserForTesting("testuser",
      new String[]{"test"});
}
 
Example 5
Source File: TestHddsDatanodeService.java    From hadoop-ozone with Apache License 2.0 5 votes vote down vote up
@Before
public void setUp() {
  testDir = GenericTestUtils.getRandomizedTestDir();
  conf = new OzoneConfiguration();
  conf.set(HddsConfigKeys.OZONE_METADATA_DIRS, testDir.getPath());
  conf.setClass(OzoneConfigKeys.HDDS_DATANODE_PLUGINS_KEY, MockService.class,
      ServicePlugin.class);

  String volumeDir = testDir + "/disk1";
  conf.set(DFSConfigKeysLegacy.DFS_DATANODE_DATA_DIR_KEY, volumeDir);
}
 
Example 6
Source File: TestHddsSecureDatanodeInit.java    From hadoop-ozone with Apache License 2.0 5 votes vote down vote up
@BeforeClass
public static void setUp() throws Exception {
  testDir = GenericTestUtils.getRandomizedTestDir();
  conf = new OzoneConfiguration();
  conf.set(HddsConfigKeys.OZONE_METADATA_DIRS, testDir.getPath());
  //conf.set(ScmConfigKeys.OZONE_SCM_NAMES, "localhost");
  String volumeDir = testDir + "/disk1";
  conf.set(DFSConfigKeysLegacy.DFS_DATANODE_DATA_DIR_KEY, volumeDir);

  conf.setBoolean(OZONE_SECURITY_ENABLED_KEY, true);
  conf.setClass(OzoneConfigKeys.HDDS_DATANODE_PLUGINS_KEY,
      TestHddsDatanodeService.MockService.class,
      ServicePlugin.class);
  securityConfig = new SecurityConfig(conf);

  service = HddsDatanodeService.createHddsDatanodeService(args);
  dnLogs = GenericTestUtils.LogCapturer.captureLogs(getLogger());
  callQuietly(() -> {
    service.start(conf);
    return null;
  });
  callQuietly(() -> {
    service.initializeCertificateClient(conf);
    return null;
  });
  certCodec = new CertificateCodec(securityConfig, DN_COMPONENT);
  keyCodec = new KeyCodec(securityConfig, DN_COMPONENT);
  dnLogs.clearOutput();
  privateKey = service.getCertificateClient().getPrivateKey();
  publicKey = service.getCertificateClient().getPublicKey();
  X509Certificate x509Certificate = null;

  x509Certificate = KeyStoreTestUtil.generateCertificate(
      "CN=Test", new KeyPair(publicKey, privateKey), 10,
      securityConfig.getSignatureAlgo());
  certHolder = new X509CertificateHolder(x509Certificate.getEncoded());

}
 
Example 7
Source File: TestKeyValueContainerCheck.java    From hadoop-ozone with Apache License 2.0 5 votes vote down vote up
@Before public void setUp() throws Exception {
  LOG.info("Testing store:{} layout:{}",
      storeImpl, chunkManagerTestInfo.getLayout());
  this.testRoot = GenericTestUtils.getRandomizedTestDir();
  conf = new OzoneConfiguration();
  conf.set(HDDS_DATANODE_DIR_KEY, testRoot.getAbsolutePath());
  conf.set(OZONE_METADATA_STORE_IMPL, storeImpl);
  chunkManagerTestInfo.updateConfig(conf);
  volumeSet = new MutableVolumeSet(UUID.randomUUID().toString(), conf);
  chunkManager = chunkManagerTestInfo.createChunkManager(true, null);
}
 
Example 8
Source File: TestKeyValueBlockIterator.java    From hadoop-ozone with Apache License 2.0 5 votes vote down vote up
@Before
public void setUp() throws Exception {
  testRoot = GenericTestUtils.getRandomizedTestDir();
  conf = new OzoneConfiguration();
  conf.set(HDDS_DATANODE_DIR_KEY, testRoot.getAbsolutePath());
  conf.set(OZONE_METADATA_STORE_IMPL, storeImpl);
  volumeSet = new MutableVolumeSet(UUID.randomUUID().toString(), conf);
}
 
Example 9
Source File: TestKeyValueHandler.java    From hadoop-ozone with Apache License 2.0 4 votes vote down vote up
@Test
public void testVolumeSetInKeyValueHandler() throws Exception{
  File path = GenericTestUtils.getRandomizedTestDir();
  OzoneConfiguration conf = new OzoneConfiguration();
  conf.set(HDDS_DATANODE_DIR_KEY, path.getAbsolutePath());
  MutableVolumeSet
      volumeSet = new MutableVolumeSet(UUID.randomUUID().toString(), conf);
  try {
    ContainerSet cset = new ContainerSet();
    int[] interval = new int[1];
    interval[0] = 2;
    ContainerMetrics metrics = new ContainerMetrics(interval);
    DatanodeDetails datanodeDetails = Mockito.mock(DatanodeDetails.class);
    DatanodeStateMachine stateMachine = Mockito.mock(
        DatanodeStateMachine.class);
    StateContext context = Mockito.mock(StateContext.class);
    Mockito.when(stateMachine.getDatanodeDetails())
        .thenReturn(datanodeDetails);
    Mockito.when(context.getParent()).thenReturn(stateMachine);
    KeyValueHandler keyValueHandler = new KeyValueHandler(conf,
        context.getParent().getDatanodeDetails().getUuidString(), cset,
        volumeSet, metrics, c -> {
    });
    assertEquals("org.apache.hadoop.ozone.container.common" +
        ".volume.RoundRobinVolumeChoosingPolicy",
        keyValueHandler.getVolumeChoosingPolicyForTesting()
            .getClass().getName());

    //Set a class which is not of sub class of VolumeChoosingPolicy
    conf.set(HDDS_DATANODE_VOLUME_CHOOSING_POLICY,
        "org.apache.hadoop.ozone.container.common.impl.HddsDispatcher");
    try {
      new KeyValueHandler(conf,
          context.getParent().getDatanodeDetails().getUuidString(),
          cset, volumeSet, metrics, c->{});
    } catch (RuntimeException ex) {
      GenericTestUtils.assertExceptionContains("class org.apache.hadoop" +
          ".ozone.container.common.impl.HddsDispatcher not org.apache" +
          ".hadoop.ozone.container.common.interfaces.VolumeChoosingPolicy",
          ex);
    }
  } finally {
    volumeSet.shutdown();
    FileUtil.fullyDelete(path);
  }
}
 
Example 10
Source File: TestKeyManagerImpl.java    From hadoop-ozone with Apache License 2.0 4 votes vote down vote up
@BeforeClass
public static void setUp() throws Exception {
  conf = new OzoneConfiguration();
  dir = GenericTestUtils.getRandomizedTestDir();
  conf.set(HddsConfigKeys.OZONE_METADATA_DIRS, dir.toString());
  conf.set(OzoneConfigKeys.OZONE_NETWORK_TOPOLOGY_AWARE_READ_KEY, "true");
  mockScmBlockLocationProtocol = mock(ScmBlockLocationProtocol.class);
  metadataManager = new OmMetadataManagerImpl(conf);
  nodeManager = new MockNodeManager(true, 10);
  NodeSchema[] schemas = new NodeSchema[]
      {ROOT_SCHEMA, RACK_SCHEMA, LEAF_SCHEMA};
  NodeSchemaManager schemaManager = NodeSchemaManager.getInstance();
  schemaManager.init(schemas, false);
  NetworkTopology clusterMap = new NetworkTopologyImpl(schemaManager);
  nodeManager.getAllNodes().stream().forEach(node -> {
    node.setNetworkName(node.getUuidString());
    clusterMap.add(node);
  });
  ((MockNodeManager)nodeManager).setNetworkTopology(clusterMap);
  SCMConfigurator configurator = new SCMConfigurator();
  configurator.setScmNodeManager(nodeManager);
  configurator.setNetworkTopology(clusterMap);
  scm = TestUtils.getScm(conf, configurator);
  scm.start();
  scm.exitSafeMode();
  scmBlockSize = (long) conf
      .getStorageSize(OZONE_SCM_BLOCK_SIZE, OZONE_SCM_BLOCK_SIZE_DEFAULT,
          StorageUnit.BYTES);
  conf.setLong(OZONE_KEY_PREALLOCATION_BLOCKS_MAX, 10);

  keyManager =
      new KeyManagerImpl(scm.getBlockProtocolServer(), metadataManager, conf,
          "om1", null);
  prefixManager = new PrefixManagerImpl(metadataManager, false);

  Mockito.when(mockScmBlockLocationProtocol
      .allocateBlock(Mockito.anyLong(), Mockito.anyInt(),
          Mockito.any(ReplicationType.class),
          Mockito.any(ReplicationFactor.class), Mockito.anyString(),
          Mockito.any(ExcludeList.class))).thenThrow(
      new SCMException("SafeModePrecheck failed for allocateBlock",
          ResultCodes.SAFE_MODE_EXCEPTION));
  createVolume(VOLUME_NAME);
  createBucket(VOLUME_NAME, BUCKET_NAME);
}
 
Example 11
Source File: TestOMStorage.java    From hadoop-ozone with Apache License 2.0 4 votes vote down vote up
public File createTestDir() {
  File dir = new File(GenericTestUtils.getRandomizedTestDir(),
      TestOMStorage.class.getSimpleName());
  dir.mkdirs();
  return dir;
}