diff --git a/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/api/Invoker.java b/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/api/Invoker.java index 520cdea8a..4afea7221 100644 --- a/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/api/Invoker.java +++ b/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/api/Invoker.java @@ -18,7 +18,11 @@ */ package org.apache.olingo.ext.proxy.api; +import java.util.concurrent.Future; + public interface Invoker { T execute(); + + Future executeAsync(); } diff --git a/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/InvokerHandler.java b/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/InvokerHandler.java index fa478f580..8db54630f 100644 --- a/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/InvokerHandler.java +++ b/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/InvokerHandler.java @@ -25,6 +25,8 @@ import java.net.URI; import java.util.ArrayList; import java.util.List; import java.util.Map; +import java.util.concurrent.Callable; +import java.util.concurrent.Future; import org.apache.commons.lang3.ArrayUtils; import org.apache.commons.lang3.StringUtils; import org.apache.olingo.client.api.communication.request.invoke.ODataNoContent; @@ -97,6 +99,16 @@ public class InvokerHandler extends AbstractInvocationHandler { return null; } + public Future executeAsync() { + return service.getClient().getConfiguration().getExecutor().submit(new Callable() { + + @Override + public T call() throws Exception { + return execute(); + } + }); + } + @SuppressWarnings({"unchecked", "rawtypes"}) public T execute() { if (operation == null || uri == null) { @@ -172,10 +184,10 @@ public class InvokerHandler extends AbstractInvocationHandler { res = Proxy.newProxyInstance( Thread.currentThread().getContextClassLoader(), new Class[] {ref}, new ComplexCollectionInvocationHandler( - service, - items, - itemRef, - null)); + service, + items, + itemRef, + null)); } else { final List items = new ArrayList(); @@ -186,10 +198,10 @@ public class InvokerHandler extends AbstractInvocationHandler { res = Proxy.newProxyInstance( Thread.currentThread().getContextClassLoader(), new Class[] {PrimitiveCollection.class}, new PrimitiveCollectionInvocationHandler( - service, - items, - null, - null)); + service, + items, + null, + null)); } } else { if (edmType.isComplexType()) { diff --git a/fit/src/test/java/org/apache/olingo/fit/proxy/v4/APIBasicDesignTestITCase.java b/fit/src/test/java/org/apache/olingo/fit/proxy/v4/APIBasicDesignTestITCase.java index 9b4288a72..5150268cf 100644 --- a/fit/src/test/java/org/apache/olingo/fit/proxy/v4/APIBasicDesignTestITCase.java +++ b/fit/src/test/java/org/apache/olingo/fit/proxy/v4/APIBasicDesignTestITCase.java @@ -16,7 +16,6 @@ * specific language governing permissions and limitations * under the License. */ - package org.apache.olingo.fit.proxy.v4; import static org.junit.Assert.assertEquals; @@ -41,12 +40,12 @@ import org.apache.olingo.ext.proxy.api.PrimitiveCollection; import org.apache.olingo.ext.proxy.api.StructuredCollectionComposableInvoker; import org.apache.olingo.ext.proxy.api.StructuredCollectionInvoker; import org.apache.olingo.ext.proxy.api.StructuredComposableInvoker; +import org.junit.Test; //CHECKSTYLE:OFF (Maven checkstyle) import org.apache.olingo.fit.proxy.v3.staticservice.microsoft.test.odata.services.astoriadefaultservice.DefaultContainer; import org.apache.olingo.fit.proxy.v3.staticservice.microsoft.test.odata.services.astoriadefaultservice.types.ContactDetailsCollection; import org.apache.olingo.fit.proxy.v3.staticservice.microsoft.test.odata.services.astoriadefaultservice.types.PhoneCollection; -import static org.apache.olingo.fit.proxy.v4.AbstractTestITCase.container; import org.apache.olingo.fit.proxy.v4.demo.odatademo.DemoService; import org.apache.olingo.fit.proxy.v4.demo.odatademo.types.PersonDetail; import org.apache.olingo.fit.proxy.v4.staticservice.microsoft.test.odata.services.odatawcfservice.InMemoryEntities; @@ -63,7 +62,6 @@ import org.apache.olingo.fit.proxy.v4.staticservice.microsoft.test.odata.service import org.apache.olingo.fit.proxy.v4.staticservice.microsoft.test.odata.services.odatawcfservice.types.ProductCollection; import org.apache.olingo.fit.proxy.v4.staticservice.microsoft.test.odata.services.odatawcfservice.types.ProductDetail; import org.apache.olingo.fit.proxy.v4.staticservice.microsoft.test.odata.services.odatawcfservice.types.ProductDetailCollection; -import org.junit.Test; //CHECKSTYLE:ON (Maven checkstyle) public class APIBasicDesignTestITCase extends AbstractTestITCase { @@ -329,7 +327,7 @@ public class APIBasicDesignTestITCase extends AbstractTestITCase { // --------------------------------------- org.apache.olingo.fit.proxy.v3.staticservice.Service v3serv = org.apache.olingo.fit.proxy.v3.staticservice.Service.getV3( - "http://localhost:9080/stub/StaticService/V30/Static.svc"); + "http://localhost:9080/stub/StaticService/V30/Static.svc"); v3serv.getClient().getConfiguration().setDefaultBatchAcceptFormat(ContentType.APPLICATION_OCTET_STREAM); final DefaultContainer v3cont = v3serv.getEntityContainer(DefaultContainer.class); assertNotNull(v3cont); @@ -390,24 +388,32 @@ public class APIBasicDesignTestITCase extends AbstractTestITCase { @Test public void workingWithOperations() { // Primitive collections (available only skip and top) - container.operations().getProductsByAccessLevel(AccessLevel.None). + final PrimitiveCollection prods1 = container.operations(). + getProductsByAccessLevel(AccessLevel.None). skip(2). top(3).execute(); + assertNotNull(prods1); + assertFalse(prods1.isEmpty()); // Complex/Entity collection (available filter, select, expand, orderBy, skip and top) - container.operations().getAllProducts(). + final ProductCollection prods2 = container.operations().getAllProducts(). filter("name eq XXXX"). select("Name", "ProductDetail"). expand("ProductDetail"). orderBy("Name").skip(3).top(5).execute(); + assertNotNull(prods2); + assertFalse(prods2.isEmpty()); // Complex/Entity (available only select and expand) - container.operations().getPerson2("London"). + final Person person = container.operations().getPerson2("London"). select("Name"). expand("Order").execute(); + assertNotNull(person); // Primitive (no query option available) - container.getAccounts().getByKey(101).getMyGiftCard().operations().getActualAmount(1.1).execute(); + final Double amount = container.getAccounts().getByKey(101).getMyGiftCard().operations(). + getActualAmount(1.1).execute(); + assertNotNull(amount); // POST ... final Address address = container.newComplexInstance(HomeAddress.class); @@ -416,14 +422,16 @@ public class APIBasicDesignTestITCase extends AbstractTestITCase { address.setCity("66010"); final AddressCollection ac = container.newComplexCollection(AddressCollection.class); - container.getCustomers().getByKey(2).operations().resetAddress(ac, 0).select("Name").expand("Orders").execute(); + final Person updated = container.getCustomers().getByKey(2).operations(). + resetAddress(ac, 0).select("Name").expand("Orders").execute(); + assertNotNull(person); } @Test public void workingWithComposableOperations() { final StructuredCollectionComposableInvoker invoker1 = container.operations().getAllProducts(); - + // Complex/Entity collection (available filter, select, expand, orderBy, skip and top) invoker1.compose().discount(10). // discount is an operation of ProductCollecton filter("Name eq XXXX"). diff --git a/fit/src/test/java/org/apache/olingo/fit/proxy/v4/AsyncTestITCase.java b/fit/src/test/java/org/apache/olingo/fit/proxy/v4/AsyncTestITCase.java index 1526170aa..dad1eaa86 100644 --- a/fit/src/test/java/org/apache/olingo/fit/proxy/v4/AsyncTestITCase.java +++ b/fit/src/test/java/org/apache/olingo/fit/proxy/v4/AsyncTestITCase.java @@ -16,7 +16,6 @@ * specific language governing permissions and limitations * under the License. */ - package org.apache.olingo.fit.proxy.v4; import static org.junit.Assert.assertEquals; @@ -29,11 +28,14 @@ import org.junit.Test; import java.util.concurrent.ExecutionException; import java.util.concurrent.Future; import org.apache.olingo.commons.api.ODataRuntimeException; +import org.apache.olingo.ext.proxy.api.StructuredCollectionComposableInvoker; +import org.apache.olingo.ext.proxy.api.StructuredComposableInvoker; //CHECKSTYLE:OFF (Maven checkstyle) import org.apache.olingo.fit.proxy.v4.staticservice.microsoft.test.odata.services.odatawcfservice.types.Customer; import org.apache.olingo.fit.proxy.v4.staticservice.microsoft.test.odata.services.odatawcfservice.types.CustomerCollection; import org.apache.olingo.fit.proxy.v4.staticservice.microsoft.test.odata.services.odatawcfservice.types.Person; +import org.apache.olingo.fit.proxy.v4.staticservice.microsoft.test.odata.services.odatawcfservice.types.ProductCollection; //CHECKSTYLE:ON (Maven checkstyle) public class AsyncTestITCase extends AbstractTestITCase { @@ -72,4 +74,30 @@ public class AsyncTestITCase extends AbstractTestITCase { final Future futurePerson = container.getPeople().getByKey(1).loadAsync(); assertEquals(randomFirstName, futurePerson.get().getFirstName()); } + + @Test + public void invoke() throws Exception { + final StructuredCollectionComposableInvoker invoker1 = + container.operations().getAllProducts(); + + final Future future1 = invoker1.compose(). + discount(10). + filter("Name eq XXXX"). + select("Name", "ProductDetail"). + expand("ProductDetail"). + orderBy("Name").skip(3).top(5).executeAsync(); + while (!future1.isDone()) { + Thread.sleep(1000L); + } + assertFalse(future1.get().isEmpty()); + + final StructuredComposableInvoker invoker2 = container.operations().getPerson2("London"); + + final Future future2 = invoker2.select("Name"). + expand("Order").executeAsync(); + while (!future2.isDone()) { + Thread.sleep(1000L); + } + assertNotNull(future2.get()); + } }