Skip to content

Commit

Permalink
Bump jclouds.version from 1.9.1 to 2.0.3 (apache#14746)
Browse files Browse the repository at this point in the history
* Updates `org.apache.jclouds:*` from 1.9.1 to 2.0.3
* Pin jclouds to 2.0.x since 2.1.x requires Guava 18+
* replace easymock with mockito

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
  • Loading branch information
xvrl and dependabot[bot] authored Aug 10, 2023
1 parent 4b9846b commit 37ed0f4
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 53 deletions.
3 changes: 3 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,6 @@ updates:
# Even then this will involve significant effort.
# See https://github.com/apache/druid/pull/12258
- dependency-name: "org.apache.calcite"
# jclouds 2.1 needs Guava 18+
- dependency-name: "org.apache.jclouds"
versions: "[2.1,)"
9 changes: 3 additions & 6 deletions extensions-contrib/cloudfiles-extensions/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,7 @@

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<jclouds.version>1.9.1</jclouds.version>
<!-- The version of guice is forced to 3.0 since JClouds 1.9.1 does not
work with guice 4.0-beta -->
<guice.version>3.0</guice.version>
<jclouds.version>2.0.0</jclouds.version>
</properties>

<dependencies>
Expand Down Expand Up @@ -151,8 +148,8 @@
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.easymock</groupId>
<artifactId>easymock</artifactId>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<scope>test</scope>
</dependency>
<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,58 +19,60 @@

package org.apache.druid.storage.cloudfiles;

import org.easymock.EasyMock;
import org.easymock.EasyMockSupport;
import org.jclouds.io.Payload;
import org.junit.Assert;
import org.junit.Test;

import java.io.IOException;
import java.io.InputStream;

public class CloudFilesByteSourceTest extends EasyMockSupport
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

public class CloudFilesByteSourceTest
{
@Test
public void openStreamTest() throws IOException
{
final String path = "path";

CloudFilesObjectApiProxy objectApi = createMock(CloudFilesObjectApiProxy.class);
CloudFilesObject cloudFilesObject = createMock(CloudFilesObject.class);
Payload payload = createMock(Payload.class);
InputStream stream = createMock(InputStream.class);
CloudFilesObjectApiProxy objectApi = mock(CloudFilesObjectApiProxy.class);
CloudFilesObject cloudFilesObject = mock(CloudFilesObject.class);
Payload payload = mock(Payload.class);
InputStream stream = mock(InputStream.class);

EasyMock.expect(objectApi.get(path, 0)).andReturn(cloudFilesObject);
EasyMock.expect(cloudFilesObject.getPayload()).andReturn(payload);
EasyMock.expect(payload.openStream()).andReturn(stream);
when(objectApi.get(path, 0)).thenReturn(cloudFilesObject);
when(cloudFilesObject.getPayload()).thenReturn(payload);
when(payload.openStream()).thenReturn(stream);
payload.close();

replayAll();

CloudFilesByteSource byteSource = new CloudFilesByteSource(objectApi, path);
Assert.assertEquals(stream, byteSource.openStream());
byteSource.closeStream();

verifyAll();
verify(objectApi).get(path, 0);
verify(cloudFilesObject).getPayload();
verify(payload).openStream();
}

@Test()
public void openStreamWithRecoverableErrorTest() throws IOException
{
final String path = "path";

CloudFilesObjectApiProxy objectApi = createMock(CloudFilesObjectApiProxy.class);
CloudFilesObject cloudFilesObject = createMock(CloudFilesObject.class);
Payload payload = createMock(Payload.class);
InputStream stream = createMock(InputStream.class);
CloudFilesObjectApiProxy objectApi = mock(CloudFilesObjectApiProxy.class);
CloudFilesObject cloudFilesObject = mock(CloudFilesObject.class);
Payload payload = mock(Payload.class);
InputStream stream = mock(InputStream.class);

EasyMock.expect(objectApi.get(path, 0)).andReturn(cloudFilesObject);
EasyMock.expect(cloudFilesObject.getPayload()).andReturn(payload);
EasyMock.expect(payload.openStream()).andThrow(new IOException()).andReturn(stream);
when(objectApi.get(path, 0)).thenReturn(cloudFilesObject);
when(cloudFilesObject.getPayload()).thenReturn(payload);
when(payload.openStream()).thenThrow(new IOException())
.thenReturn(stream);
payload.close();

replayAll();

CloudFilesByteSource byteSource = new CloudFilesByteSource(objectApi, path);
try {
byteSource.openStream();
Expand All @@ -82,6 +84,8 @@ public void openStreamWithRecoverableErrorTest() throws IOException
Assert.assertEquals(stream, byteSource.openStream());
byteSource.closeStream();

verifyAll();
verify(objectApi).get(path, 0);
verify(cloudFilesObject).getPayload();
verify(payload, times(2)).openStream();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
import org.apache.druid.java.util.common.Intervals;
import org.apache.druid.timeline.DataSegment;
import org.apache.druid.timeline.partition.NoneShardSpec;
import org.easymock.EasyMock;
import org.jclouds.openstack.swift.v1.features.ObjectApi;
import org.jclouds.rackspace.cloudfiles.v1.CloudFilesApi;
import org.junit.Assert;
Expand All @@ -36,6 +35,12 @@
import java.util.ArrayList;
import java.util.HashMap;

import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.atLeastOnce;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

/**
*/
public class CloudFilesDataSegmentPusherTest
Expand All @@ -46,16 +51,12 @@ public class CloudFilesDataSegmentPusherTest
@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);
ObjectApi objectApi = mock(ObjectApi.class);
when(objectApi.put(any(), any())).thenReturn(null);

CloudFilesApi api = mock(CloudFilesApi.class);
when(api.getObjectApi(any(), any()))
.thenReturn(objectApi);

CloudFilesDataSegmentPusherConfig config = new CloudFilesDataSegmentPusherConfig();
config.setRegion("region");
Expand Down Expand Up @@ -87,6 +88,7 @@ public void testPush() throws Exception

Assert.assertEquals(segmentToPush.getSize(), segment.getSize());

EasyMock.verify(api);
verify(objectApi, atLeastOnce()).put(any(), any());
verify(api, atLeastOnce()).getObjectApi(any(), any());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,18 @@

package org.apache.druid.storage.cloudfiles;

import org.easymock.EasyMock;
import org.easymock.EasyMockSupport;
import org.jclouds.io.Payload;
import org.jclouds.openstack.swift.v1.domain.SwiftObject;
import org.jclouds.openstack.swift.v1.features.ObjectApi;
import org.jclouds.rackspace.cloudfiles.v1.CloudFilesApi;
import org.junit.Assert;
import org.junit.Test;

public class CloudFilesObjectApiProxyTest extends EasyMockSupport
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

public class CloudFilesObjectApiProxyTest
{
@Test
public void getTest()
Expand All @@ -37,16 +39,14 @@ public void getTest()
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);
CloudFilesApi cloudFilesApi = mock(CloudFilesApi.class);
ObjectApi objectApi = mock(ObjectApi.class);
SwiftObject swiftObject = mock(SwiftObject.class);
Payload payload = mock(Payload.class);

replayAll();
when(cloudFilesApi.getObjectApi(region, container)).thenReturn(objectApi);
when(objectApi.get(path)).thenReturn(swiftObject);
when(swiftObject.getPayload()).thenReturn(payload);

CloudFilesObjectApiProxy cfoApiProxy = new CloudFilesObjectApiProxy(cloudFilesApi, region, container);
CloudFilesObject cloudFilesObject = cfoApiProxy.get(path, 0);
Expand All @@ -56,6 +56,8 @@ public void getTest()
Assert.assertEquals(cloudFilesObject.getContainer(), container);
Assert.assertEquals(cloudFilesObject.getPath(), path);

verifyAll();
verify(cloudFilesApi).getObjectApi(region, container);
verify(objectApi).get(path);
verify(swiftObject).getPayload();
}
}

0 comments on commit 37ed0f4

Please sign in to comment.