Search in sources :

Example 1 with ObjectApi

use of org.jclouds.openstack.swift.v1.features.ObjectApi in project druid by druid-io.

the class CloudFilesDataSegmentPusherTest method testPush.

@Test
public void testPush() throws Exception {
    ObjectApi objectApi = EasyMock.createStrictMock(ObjectApi.class);
    EasyMock.expect(objectApi.put(EasyMock.anyString(), EasyMock.<Payload>anyObject())).andReturn(null).atLeastOnce();
    EasyMock.replay(objectApi);
    CloudFilesApi api = EasyMock.createStrictMock(CloudFilesApi.class);
    EasyMock.expect(api.getObjectApi(EasyMock.anyString(), EasyMock.anyString())).andReturn(objectApi).atLeastOnce();
    EasyMock.replay(api);
    CloudFilesDataSegmentPusherConfig config = new CloudFilesDataSegmentPusherConfig();
    config.setRegion("region");
    config.setContainer("container");
    config.setBasePath("basePath");
    CloudFilesDataSegmentPusher pusher = new CloudFilesDataSegmentPusher(api, config, new DefaultObjectMapper());
    // Create a mock segment on disk
    File tmp = tempFolder.newFile("version.bin");
    final byte[] data = new byte[] { 0x0, 0x0, 0x0, 0x1 };
    Files.write(data, tmp);
    final long size = data.length;
    DataSegment segmentToPush = new DataSegment("foo", new Interval("2015/2016"), "0", Maps.<String, Object>newHashMap(), Lists.<String>newArrayList(), Lists.<String>newArrayList(), NoneShardSpec.instance(), 0, size);
    DataSegment segment = pusher.push(tempFolder.getRoot(), segmentToPush);
    Assert.assertEquals(segmentToPush.getSize(), segment.getSize());
    EasyMock.verify(api);
}
Also used : ObjectApi(org.jclouds.openstack.swift.v1.features.ObjectApi) Payload(org.jclouds.io.Payload) CloudFilesApi(org.jclouds.rackspace.cloudfiles.v1.CloudFilesApi) DefaultObjectMapper(io.druid.jackson.DefaultObjectMapper) File(java.io.File) DataSegment(io.druid.timeline.DataSegment) Interval(org.joda.time.Interval) Test(org.junit.Test)

Example 2 with ObjectApi

use of org.jclouds.openstack.swift.v1.features.ObjectApi in project druid by druid-io.

the class CloudFilesObjectApiProxyTest method getTest.

@Test
public void getTest() {
    final String path = "path";
    final String region = "region";
    final String container = "container";
    CloudFilesApi cloudFilesApi = createMock(CloudFilesApi.class);
    ObjectApi objectApi = createMock(ObjectApi.class);
    SwiftObject swiftObject = createMock(SwiftObject.class);
    Payload payload = createMock(Payload.class);
    expect(cloudFilesApi.getObjectApi(region, container)).andReturn(objectApi);
    expect(objectApi.get(path)).andReturn(swiftObject);
    expect(swiftObject.getPayload()).andReturn(payload);
    replayAll();
    CloudFilesObjectApiProxy cfoApiProxy = new CloudFilesObjectApiProxy(cloudFilesApi, region, container);
    CloudFilesObject cloudFilesObject = cfoApiProxy.get(path);
    assertEquals(cloudFilesObject.getPayload(), payload);
    assertEquals(cloudFilesObject.getRegion(), region);
    assertEquals(cloudFilesObject.getContainer(), container);
    assertEquals(cloudFilesObject.getPath(), path);
    verifyAll();
}
Also used : ObjectApi(org.jclouds.openstack.swift.v1.features.ObjectApi) SwiftObject(org.jclouds.openstack.swift.v1.domain.SwiftObject) CloudFilesApi(org.jclouds.rackspace.cloudfiles.v1.CloudFilesApi) Payload(org.jclouds.io.Payload) Test(org.junit.Test)

Example 3 with ObjectApi

use of org.jclouds.openstack.swift.v1.features.ObjectApi in project druid by druid-io.

the class CloudFilesDataSegmentPusherTest method testPush.

@Test
public void testPush() throws Exception {
    ObjectApi objectApi = EasyMock.createStrictMock(ObjectApi.class);
    EasyMock.expect(objectApi.put(EasyMock.anyString(), EasyMock.anyObject())).andReturn(null).atLeastOnce();
    EasyMock.replay(objectApi);
    CloudFilesApi api = EasyMock.createStrictMock(CloudFilesApi.class);
    EasyMock.expect(api.getObjectApi(EasyMock.anyString(), EasyMock.anyString())).andReturn(objectApi).atLeastOnce();
    EasyMock.replay(api);
    CloudFilesDataSegmentPusherConfig config = new CloudFilesDataSegmentPusherConfig();
    config.setRegion("region");
    config.setContainer("container");
    config.setBasePath("basePath");
    CloudFilesDataSegmentPusher pusher = new CloudFilesDataSegmentPusher(api, config, new DefaultObjectMapper());
    // Create a mock segment on disk
    File tmp = tempFolder.newFile("version.bin");
    final byte[] data = new byte[] { 0x0, 0x0, 0x0, 0x1 };
    Files.write(data, tmp);
    final long size = data.length;
    DataSegment segmentToPush = new DataSegment("foo", Intervals.of("2015/2016"), "0", new HashMap<>(), new ArrayList<>(), new ArrayList<>(), NoneShardSpec.instance(), 0, size);
    DataSegment segment = pusher.push(tempFolder.getRoot(), segmentToPush, false);
    Assert.assertEquals(segmentToPush.getSize(), segment.getSize());
    EasyMock.verify(api);
}
Also used : ObjectApi(org.jclouds.openstack.swift.v1.features.ObjectApi) CloudFilesApi(org.jclouds.rackspace.cloudfiles.v1.CloudFilesApi) DefaultObjectMapper(org.apache.druid.jackson.DefaultObjectMapper) File(java.io.File) DataSegment(org.apache.druid.timeline.DataSegment) Test(org.junit.Test)

Example 4 with ObjectApi

use of org.jclouds.openstack.swift.v1.features.ObjectApi in project druid by druid-io.

the class CloudFilesObjectApiProxyTest method getTest.

@Test
public void getTest() {
    final String path = "path";
    final String region = "region";
    final String container = "container";
    CloudFilesApi cloudFilesApi = createMock(CloudFilesApi.class);
    ObjectApi objectApi = createMock(ObjectApi.class);
    SwiftObject swiftObject = createMock(SwiftObject.class);
    Payload payload = createMock(Payload.class);
    EasyMock.expect(cloudFilesApi.getObjectApi(region, container)).andReturn(objectApi);
    EasyMock.expect(objectApi.get(path)).andReturn(swiftObject);
    EasyMock.expect(swiftObject.getPayload()).andReturn(payload);
    replayAll();
    CloudFilesObjectApiProxy cfoApiProxy = new CloudFilesObjectApiProxy(cloudFilesApi, region, container);
    CloudFilesObject cloudFilesObject = cfoApiProxy.get(path, 0);
    Assert.assertEquals(cloudFilesObject.getPayload(), payload);
    Assert.assertEquals(cloudFilesObject.getRegion(), region);
    Assert.assertEquals(cloudFilesObject.getContainer(), container);
    Assert.assertEquals(cloudFilesObject.getPath(), path);
    verifyAll();
}
Also used : ObjectApi(org.jclouds.openstack.swift.v1.features.ObjectApi) SwiftObject(org.jclouds.openstack.swift.v1.domain.SwiftObject) CloudFilesApi(org.jclouds.rackspace.cloudfiles.v1.CloudFilesApi) Payload(org.jclouds.io.Payload) Test(org.junit.Test)

Aggregations

ObjectApi (org.jclouds.openstack.swift.v1.features.ObjectApi)4 CloudFilesApi (org.jclouds.rackspace.cloudfiles.v1.CloudFilesApi)4 Test (org.junit.Test)4 Payload (org.jclouds.io.Payload)3 File (java.io.File)2 SwiftObject (org.jclouds.openstack.swift.v1.domain.SwiftObject)2 DefaultObjectMapper (io.druid.jackson.DefaultObjectMapper)1 DataSegment (io.druid.timeline.DataSegment)1 DefaultObjectMapper (org.apache.druid.jackson.DefaultObjectMapper)1 DataSegment (org.apache.druid.timeline.DataSegment)1 Interval (org.joda.time.Interval)1