From ffeaa2feb811081551b7187f414062efc0da0f49 Mon Sep 17 00:00:00 2001 From: Adam Lowe Date: Wed, 28 Mar 2012 14:34:15 +0100 Subject: [PATCH 1/3] Ensuring annotation processor finds the correct async client method --- .../rest/internal/RestAnnotationProcessor.java | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/core/src/main/java/org/jclouds/rest/internal/RestAnnotationProcessor.java b/core/src/main/java/org/jclouds/rest/internal/RestAnnotationProcessor.java index 1564b57ce8..5e0566e76d 100644 --- a/core/src/main/java/org/jclouds/rest/internal/RestAnnotationProcessor.java +++ b/core/src/main/java/org/jclouds/rest/internal/RestAnnotationProcessor.java @@ -348,7 +348,7 @@ public class RestAnnotationProcessor { public int hashCode() { final int prime = 31; int result = 1; - result = prime * result + ((declaringPackage == null) ? 0 : declaringPackage.hashCode()); + result = prime * result + ((declaringClass == null) ? 0 : declaringClass.hashCode()); result = prime * result + ((name == null) ? 0 : name.hashCode()); result = prime * result + parametersTypeHashCode; return result; @@ -363,10 +363,10 @@ public class RestAnnotationProcessor { if (getClass() != obj.getClass()) return false; MethodKey other = (MethodKey) obj; - if (declaringPackage == null) { - if (other.declaringPackage != null) + if (declaringClass == null) { + if (other.declaringClass != null) return false; - } else if (!declaringPackage.equals(other.declaringPackage)) + } else if (!declaringClass.equals(other.declaringClass)) return false; if (name == null) { if (other.name != null) @@ -380,11 +380,11 @@ public class RestAnnotationProcessor { private final String name; private final int parametersTypeHashCode; - private final Package declaringPackage; + private final Class declaringClass; public MethodKey(Method method) { this.name = method.getName(); - this.declaringPackage = method.getDeclaringClass().getPackage(); + this.declaringClass = method.getDeclaringClass(); int parametersTypeHashCode = 0; for (Class param : method.getParameterTypes()) parametersTypeHashCode += param.hashCode(); From 047662a4b1fc8edf6b3f5e72da36fd8ce74cae32 Mon Sep 17 00:00:00 2001 From: Adam Lowe Date: Tue, 10 Apr 2012 08:06:30 +0100 Subject: [PATCH 2/3] Test to check annotation processor finds the correct async client method --- .../internal/RestAnnotationProcessorTest.java | 42 ++++++++++++++----- 1 file changed, 32 insertions(+), 10 deletions(-) diff --git a/core/src/test/java/org/jclouds/rest/internal/RestAnnotationProcessorTest.java b/core/src/test/java/org/jclouds/rest/internal/RestAnnotationProcessorTest.java index d30a5a1894..a7637aa065 100644 --- a/core/src/test/java/org/jclouds/rest/internal/RestAnnotationProcessorTest.java +++ b/core/src/test/java/org/jclouds/rest/internal/RestAnnotationProcessorTest.java @@ -180,7 +180,7 @@ public class RestAnnotationProcessorTest extends BaseRestClientTest { @ConfiguresRestClient protected static class CallerModule extends RestClientModule { CallerModule() { - super(Caller.class, AsyncCaller.class, ImmutableMap., Class> of(Callee.class, AsyncCallee.class)); + super(Caller.class, AsyncCaller.class, ImmutableMap., Class> of(Callee.class, AsyncCallee.class, Callee2.class, AsyncCallee2.class)); } @Override @@ -199,7 +199,14 @@ public class RestAnnotationProcessorTest extends BaseRestClientTest { @Path("/{path}") ListenableFuture onePath(@PathParam("path") String path); } - + + @Path("/client/{jclouds.api-version}") + public static interface AsyncCallee2 { + @GET + @Path("/{path}/2") + ListenableFuture onePath(@PathParam("path") String path); + } + @Endpoint(Localhost2.class) @Timeout(duration = 10, timeUnit = TimeUnit.NANOSECONDS) public static interface Caller { @@ -212,6 +219,9 @@ public class RestAnnotationProcessorTest extends BaseRestClientTest { @Delegate public Callee getCallee(); + @Delegate + public Callee2 getCallee2(); + @Delegate public Callee getCallee(@EndpointParam URI endpoint); @@ -224,6 +234,12 @@ public class RestAnnotationProcessorTest extends BaseRestClientTest { void onePath(String path); } + + @Timeout(duration = 10, timeUnit = TimeUnit.NANOSECONDS) + public static interface Callee2 { + + void onePath(String path); + } public static interface AsyncCaller { @Provides @@ -233,6 +249,9 @@ public class RestAnnotationProcessorTest extends BaseRestClientTest { @Delegate public AsyncCallee getCallee(); + @Delegate + public AsyncCallee2 getCallee2(); + @Delegate public AsyncCallee getCallee(@EndpointParam URI endpoint); @@ -267,14 +286,14 @@ public class RestAnnotationProcessorTest extends BaseRestClientTest { public void testDelegateIsLazyLoadedAndRequestIncludesVersionAndPath() throws InterruptedException, ExecutionException { Injector child = injectorForCaller(new HttpCommandExecutorService() { - + int callCounter=0; @Override public Future submit(HttpCommand command) { - assertEquals(command.getCurrentRequest().getRequestLine(), - "GET http://localhost:1111/client/1/foo HTTP/1.1"); + if (callCounter == 1) assertEquals(command.getCurrentRequest().getRequestLine(), "GET http://localhost:1111/client/1/bar/2 HTTP/1.1"); + else assertEquals(command.getCurrentRequest().getRequestLine(), "GET http://localhost:1111/client/1/foo HTTP/1.1"); + callCounter++; return Futures.immediateFuture(HttpResponse.builder().build()); } - }); try { @@ -283,10 +302,13 @@ public class RestAnnotationProcessorTest extends BaseRestClientTest { } catch (ConfigurationException e) { } - - child.getInstance(Caller.class).getCallee().onePath("foo"); - child.getInstance(Caller.class).getCallee().onePath("foo"); - + + Caller caller = child.getInstance(Caller.class); + + caller.getCallee().onePath("foo"); + caller.getCallee2().onePath("bar"); + // Note this used to result in "http://localhost:1111/client/1/foo/2"! + caller.getCallee().onePath("foo"); } public void testAsyncDelegateIsLazyLoadedAndRequestIncludesEndpointVersionAndPath() throws InterruptedException, From bae9633d23b3fdf6bf3357d5098bd89678dd866f Mon Sep 17 00:00:00 2001 From: Adam Lowe Date: Tue, 10 Apr 2012 08:12:40 +0100 Subject: [PATCH 3/3] Test to check annotation processor finds the correct async client method --- .../rest/internal/RestAnnotationProcessorTest.java | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/core/src/test/java/org/jclouds/rest/internal/RestAnnotationProcessorTest.java b/core/src/test/java/org/jclouds/rest/internal/RestAnnotationProcessorTest.java index a7637aa065..52745c9e10 100644 --- a/core/src/test/java/org/jclouds/rest/internal/RestAnnotationProcessorTest.java +++ b/core/src/test/java/org/jclouds/rest/internal/RestAnnotationProcessorTest.java @@ -302,13 +302,11 @@ public class RestAnnotationProcessorTest extends BaseRestClientTest { } catch (ConfigurationException e) { } - - Caller caller = child.getInstance(Caller.class); - - caller.getCallee().onePath("foo"); - caller.getCallee2().onePath("bar"); - // Note this used to result in "http://localhost:1111/client/1/foo/2"! - caller.getCallee().onePath("foo"); + + child.getInstance(Caller.class).getCallee().onePath("foo"); + child.getInstance(Caller.class).getCallee2().onePath("bar"); + // Note if wrong method is picked up, we'll see "http://localhost:1111/client/1/foo/2"! + child.getInstance(Caller.class).getCallee().onePath("foo"); } public void testAsyncDelegateIsLazyLoadedAndRequestIncludesEndpointVersionAndPath() throws InterruptedException,