Search in sources :

Example 11 with SwiftObjectPath

use of org.apache.hadoop.fs.swift.util.SwiftObjectPath in project hadoop by apache.

the class TestSwiftObjectPath method testRootDirProbeRootPath.

@Test(timeout = SWIFT_TEST_TIMEOUT)
public void testRootDirProbeRootPath() throws Throwable {
    SwiftObjectPath object = new SwiftObjectPath("container", "/");
    assertTrue(SwiftUtils.isRootDir(object));
}
Also used : SwiftObjectPath(org.apache.hadoop.fs.swift.util.SwiftObjectPath) Test(org.junit.Test)

Example 12 with SwiftObjectPath

use of org.apache.hadoop.fs.swift.util.SwiftObjectPath in project hadoop by apache.

the class TestSwiftObjectPath method testRootDirProbeEmptyPath.

@Test(timeout = SWIFT_TEST_TIMEOUT)
public void testRootDirProbeEmptyPath() throws Throwable {
    SwiftObjectPath object = new SwiftObjectPath("container", "");
    assertTrue(SwiftUtils.isRootDir(object));
}
Also used : SwiftObjectPath(org.apache.hadoop.fs.swift.util.SwiftObjectPath) Test(org.junit.Test)

Example 13 with SwiftObjectPath

use of org.apache.hadoop.fs.swift.util.SwiftObjectPath in project hadoop by apache.

the class TestSwiftObjectPath method testChildOfProbe.

@Test(timeout = SWIFT_TEST_TIMEOUT)
public void testChildOfProbe() throws Throwable {
    SwiftObjectPath parent = new SwiftObjectPath("container", "/parent");
    SwiftObjectPath parent2 = new SwiftObjectPath("container", "/parent2");
    SwiftObjectPath child = new SwiftObjectPath("container", "/parent/child");
    SwiftObjectPath sibling = new SwiftObjectPath("container", "/parent/sibling");
    SwiftObjectPath grandchild = new SwiftObjectPath("container", "/parent/child/grandchild");
    assertParentOf(parent, child);
    assertParentOf(parent, grandchild);
    assertParentOf(child, grandchild);
    assertParentOf(parent, parent);
    assertNotParentOf(child, parent);
    assertParentOf(child, child);
    assertNotParentOf(parent, parent2);
    assertNotParentOf(grandchild, parent);
}
Also used : SwiftObjectPath(org.apache.hadoop.fs.swift.util.SwiftObjectPath) Test(org.junit.Test)

Example 14 with SwiftObjectPath

use of org.apache.hadoop.fs.swift.util.SwiftObjectPath in project hadoop by apache.

the class TestSwiftObjectPath method testParseUrlPath.

@Test(timeout = SWIFT_TEST_TIMEOUT)
public void testParseUrlPath() throws Exception {
    final String pathString = "swift://container.service1/home/user/files/file1";
    final URI uri = new URI(pathString);
    final Path path = new Path(pathString);
    final SwiftObjectPath expected = SwiftObjectPath.fromPath(uri, path);
    final SwiftObjectPath actual = new SwiftObjectPath(RestClientBindings.extractContainerName(uri), "/home/user/files/file1");
    assertEquals(expected, actual);
}
Also used : Path(org.apache.hadoop.fs.Path) SwiftObjectPath(org.apache.hadoop.fs.swift.util.SwiftObjectPath) URI(java.net.URI) SwiftObjectPath(org.apache.hadoop.fs.swift.util.SwiftObjectPath) Test(org.junit.Test)

Example 15 with SwiftObjectPath

use of org.apache.hadoop.fs.swift.util.SwiftObjectPath in project hadoop by apache.

the class TestSwiftRestClient method testPutAndDelete.

@Test(timeout = SWIFT_TEST_TIMEOUT)
public void testPutAndDelete() throws Throwable {
    assumeEnabled();
    SwiftRestClient client = createClient();
    client.authenticate();
    Path path = new Path("restTestPutAndDelete");
    SwiftObjectPath sobject = SwiftObjectPath.fromPath(serviceURI, path);
    byte[] stuff = new byte[1];
    stuff[0] = 'a';
    client.upload(sobject, new ByteArrayInputStream(stuff), stuff.length);
    //check file exists
    Duration head = new Duration();
    Header[] responseHeaders = client.headRequest("expect success", sobject, SwiftRestClient.NEWEST);
    head.finished();
    LOG.info("head request duration " + head);
    for (Header header : responseHeaders) {
        LOG.info(header.toString());
    }
    //delete the file
    client.delete(sobject);
    //check file is gone
    try {
        Header[] headers = client.headRequest("expect fail", sobject, SwiftRestClient.NEWEST);
        Assert.fail("Expected deleted file, but object is still present: " + sobject);
    } catch (FileNotFoundException e) {
    //expected
    }
    for (DurationStats stats : client.getOperationStatistics()) {
        LOG.info(stats);
    }
}
Also used : Path(org.apache.hadoop.fs.Path) SwiftObjectPath(org.apache.hadoop.fs.swift.util.SwiftObjectPath) DurationStats(org.apache.hadoop.fs.swift.util.DurationStats) Header(org.apache.commons.httpclient.Header) ByteArrayInputStream(java.io.ByteArrayInputStream) FileNotFoundException(java.io.FileNotFoundException) Duration(org.apache.hadoop.fs.swift.util.Duration) SwiftObjectPath(org.apache.hadoop.fs.swift.util.SwiftObjectPath) Test(org.junit.Test)

Aggregations

SwiftObjectPath (org.apache.hadoop.fs.swift.util.SwiftObjectPath)15 Test (org.junit.Test)10 Path (org.apache.hadoop.fs.Path)8 FileNotFoundException (java.io.FileNotFoundException)4 URI (java.net.URI)4 Header (org.apache.commons.httpclient.Header)2 FileStatus (org.apache.hadoop.fs.FileStatus)2 CollectionType (com.fasterxml.jackson.databind.type.CollectionType)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 ParseException (java.text.ParseException)1 SimpleDateFormat (java.text.SimpleDateFormat)1 ArrayList (java.util.ArrayList)1 FileAlreadyExistsException (org.apache.hadoop.fs.FileAlreadyExistsException)1 SwiftException (org.apache.hadoop.fs.swift.exceptions.SwiftException)1 SwiftInvalidResponseException (org.apache.hadoop.fs.swift.exceptions.SwiftInvalidResponseException)1 SwiftOperationFailedException (org.apache.hadoop.fs.swift.exceptions.SwiftOperationFailedException)1 Duration (org.apache.hadoop.fs.swift.util.Duration)1 DurationStats (org.apache.hadoop.fs.swift.util.DurationStats)1