Search in sources :

Example 1 with ErasureCodingAction

use of org.smartdata.hdfs.action.ErasureCodingAction in project SSM by Intel-bigdata.

the class TestSmartDFSClientReadECData method testReadECDataCreatedBySSM.

@Test
public void testReadECDataCreatedBySSM() throws IOException {
    cluster.getFileSystem().mkdirs(new Path(TEST_DIR));
    String srcPath = "/ec/a.txt";
    createTestFile(srcPath, 300000);
    SmartConf smartConf = smartContext.getConf();
    // The below single configuration is in order to make sure a SmartDFSClient can be created
    // successfully, and the actual value for this property does't matter.
    smartConf.set(SmartConfKeys.SMART_SERVER_RPC_ADDRESS_KEY, SmartConfKeys.SMART_SERVER_RPC_ADDRESS_DEFAULT);
    SmartDFSClient smartDFSClient = new SmartDFSClient(smartConf);
    ErasureCodingAction ecAction = new ErasureCodingAction();
    ecAction.setContext(smartContext);
    String ecTmpPath = "/ssm/ec_tmp/tmp_file";
    Map<String, String> args = new HashMap<>();
    args.put(HdfsAction.FILE_PATH, srcPath);
    args.put(ErasureCodingBase.EC_TMP, ecTmpPath);
    args.put(ErasureCodingAction.EC_POLICY_NAME, ecPolicy.getName());
    ecAction.init(args);
    ecAction.run();
    assertTrue(ecAction.getExpectedAfterRun());
    Assert.assertTrue(ecPolicy == dfsClient.getErasureCodingPolicy(srcPath));
    DFSInputStream dfsInputStream = smartDFSClient.open(srcPath);
    // In unit test, a DFSInputStream can still be used to read EC data. But in real environment,
    // DFSStripedInputStream is required, otherwise, block not found exception will occur.
    Assert.assertTrue(dfsInputStream instanceof DFSStripedInputStream);
    int bufferSize = 64 * 1024;
    byte[] buffer = new byte[bufferSize];
    // Read EC data from HDFS
    while (dfsInputStream.read(buffer, 0, bufferSize) != -1) {
    }
    dfsInputStream.close();
}
Also used : Path(org.apache.hadoop.fs.Path) HashMap(java.util.HashMap) DFSStripedInputStream(org.apache.hadoop.hdfs.DFSStripedInputStream) SmartConf(org.smartdata.conf.SmartConf) DFSInputStream(org.apache.hadoop.hdfs.DFSInputStream) ErasureCodingAction(org.smartdata.hdfs.action.ErasureCodingAction) SmartDFSClient(org.smartdata.hdfs.client.SmartDFSClient) Test(org.junit.Test)

Aggregations

HashMap (java.util.HashMap)1 Path (org.apache.hadoop.fs.Path)1 DFSInputStream (org.apache.hadoop.hdfs.DFSInputStream)1 DFSStripedInputStream (org.apache.hadoop.hdfs.DFSStripedInputStream)1 Test (org.junit.Test)1 SmartConf (org.smartdata.conf.SmartConf)1 ErasureCodingAction (org.smartdata.hdfs.action.ErasureCodingAction)1 SmartDFSClient (org.smartdata.hdfs.client.SmartDFSClient)1