You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@olingo.apache.org by mi...@apache.org on 2014/07/26 12:22:09 UTC
[22/32] git commit: [OLINGO-368] Adding async calls for operation
invoke, after OLINGO-366
[OLINGO-368] Adding async calls for operation invoke, after OLINGO-366
Project: http://git-wip-us.apache.org/repos/asf/olingo-odata4/repo
Commit: http://git-wip-us.apache.org/repos/asf/olingo-odata4/commit/6d51eef3
Tree: http://git-wip-us.apache.org/repos/asf/olingo-odata4/tree/6d51eef3
Diff: http://git-wip-us.apache.org/repos/asf/olingo-odata4/diff/6d51eef3
Branch: refs/heads/OLINGO-377-FIT
Commit: 6d51eef303e587cbddd5da74b8356271d1d43c8d
Parents: 86d3338
Author: Francesco Chicchiriccò <--global>
Authored: Fri Jul 25 11:24:57 2014 +0200
Committer: Francesco Chicchiriccò <--global>
Committed: Fri Jul 25 11:24:57 2014 +0200
----------------------------------------------------------------------
.../apache/olingo/ext/proxy/api/Invoker.java | 4 +++
.../ext/proxy/commons/InvokerHandler.java | 28 ++++++++++++------
.../fit/proxy/v4/APIBasicDesignTestITCase.java | 28 +++++++++++-------
.../olingo/fit/proxy/v4/AsyncTestITCase.java | 30 +++++++++++++++++++-
4 files changed, 71 insertions(+), 19 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/6d51eef3/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/api/Invoker.java
----------------------------------------------------------------------
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 520cdea..4afea72 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> {
T execute();
+
+ Future<T> executeAsync();
}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/6d51eef3/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/InvokerHandler.java
----------------------------------------------------------------------
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 fa478f5..8db5463 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<T, C> extends AbstractInvocationHandler {
return null;
}
+ public Future<T> executeAsync() {
+ return service.getClient().getConfiguration().getExecutor().submit(new Callable<T>() {
+
+ @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<T, C> 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<T, C> 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()) {
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/6d51eef3/fit/src/test/java/org/apache/olingo/fit/proxy/v4/APIBasicDesignTestITCase.java
----------------------------------------------------------------------
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 9b4288a..5150268 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<org.apache.olingo.client.api.v3.EdmEnabledODataClient> 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<String> 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<ProductCollection, ProductCollection.Operations> 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").
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/6d51eef3/fit/src/test/java/org/apache/olingo/fit/proxy/v4/AsyncTestITCase.java
----------------------------------------------------------------------
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 1526170..dad1eaa 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<Person> futurePerson = container.getPeople().getByKey(1).loadAsync();
assertEquals(randomFirstName, futurePerson.get().getFirstName());
}
+
+ @Test
+ public void invoke() throws Exception {
+ final StructuredCollectionComposableInvoker<ProductCollection, ProductCollection.Operations> invoker1 =
+ container.operations().getAllProducts();
+
+ final Future<ProductCollection> 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<Person, Person.Operations> invoker2 = container.operations().getPerson2("London");
+
+ final Future<Person> future2 = invoker2.select("Name").
+ expand("Order").executeAsync();
+ while (!future2.isDone()) {
+ Thread.sleep(1000L);
+ }
+ assertNotNull(future2.get());
+ }
}