[OLINGO-368] Adding async calls for operation invoke, after OLINGO-366
This commit is contained in:
parent
86d33380e8
commit
6d51eef303
|
@ -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();
|
||||
}
|
||||
|
|
|
@ -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()) {
|
||||
|
|
|
@ -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").
|
||||
|
|
|
@ -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());
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue