From fc42d2ad57d9d612d04a8f52d2ac68ae91a51ad7 Mon Sep 17 00:00:00 2001 From: fmartelli Date: Mon, 12 May 2014 11:55:18 +0200 Subject: [PATCH] [OLINGO-260] fix for integration test deadlock --- ext/pojogen-maven-plugin/pom.xml | 7 - .../v3/AuthEntityRetrieveTestITCase.java | 14 +- .../fit/proxy/v3/EntityCreateTestITCase.java | 247 +++++++++--------- .../v4/AuthEntityRetrieveTestITCase.java | 28 +- .../olingo/fit/v3/EntityCreateTestITCase.java | 2 +- .../olingo/client/core/uri/URIUtils.java | 14 +- 6 files changed, 156 insertions(+), 156 deletions(-) diff --git a/ext/pojogen-maven-plugin/pom.xml b/ext/pojogen-maven-plugin/pom.xml index f0fc429e7..3a77451e2 100644 --- a/ext/pojogen-maven-plugin/pom.xml +++ b/ext/pojogen-maven-plugin/pom.xml @@ -110,13 +110,6 @@ src/main/resources true - - .. - META-INF - - LICENSE - - diff --git a/fit/src/test/java/org/apache/olingo/fit/proxy/v3/AuthEntityRetrieveTestITCase.java b/fit/src/test/java/org/apache/olingo/fit/proxy/v3/AuthEntityRetrieveTestITCase.java index 40543e9e5..cca4f1f45 100644 --- a/fit/src/test/java/org/apache/olingo/fit/proxy/v3/AuthEntityRetrieveTestITCase.java +++ b/fit/src/test/java/org/apache/olingo/fit/proxy/v3/AuthEntityRetrieveTestITCase.java @@ -19,11 +19,11 @@ package org.apache.olingo.fit.proxy.v3; import static org.junit.Assert.assertNotNull; + import org.junit.AfterClass; import org.junit.BeforeClass; import org.apache.olingo.client.core.http.BasicAuthHttpClientFactory; -import org.apache.olingo.client.core.http.DefaultHttpClientFactory; import org.apache.olingo.ext.proxy.EntityContainerFactory; import org.apache.olingo.fit.proxy.v3.staticservice.microsoft.test.odata.services.astoriadefaultservice. DefaultContainer; @@ -31,19 +31,17 @@ import org.apache.olingo.fit.proxy.v3.staticservice.microsoft.test.odata.service public class AuthEntityRetrieveTestITCase extends EntityRetrieveTestITCase { @BeforeClass - public static void enableBasicAuth() { + public static void setupContaner() { + containerFactory = EntityContainerFactory.getV3(testAuthServiceRootURL); containerFactory.getConfiguration(). setHttpClientFactory(new BasicAuthHttpClientFactory("odatajclient", "odatajclient")); + container = containerFactory.getEntityContainer(DefaultContainer.class); + assertNotNull(container); } @AfterClass public static void disableBasicAuth() { - containerFactory.getConfiguration().setHttpClientFactory(new DefaultHttpClientFactory()); - } - - @BeforeClass - public static void setupContaner() { - containerFactory = EntityContainerFactory.getV3(testAuthServiceRootURL); + containerFactory = EntityContainerFactory.getV3(testStaticServiceRootURL); container = containerFactory.getEntityContainer(DefaultContainer.class); assertNotNull(container); } diff --git a/fit/src/test/java/org/apache/olingo/fit/proxy/v3/EntityCreateTestITCase.java b/fit/src/test/java/org/apache/olingo/fit/proxy/v3/EntityCreateTestITCase.java index 3ef269123..41187060c 100644 --- a/fit/src/test/java/org/apache/olingo/fit/proxy/v3/EntityCreateTestITCase.java +++ b/fit/src/test/java/org/apache/olingo/fit/proxy/v3/EntityCreateTestITCase.java @@ -18,6 +18,7 @@ */ package org.apache.olingo.fit.proxy.v3; +import static org.apache.olingo.fit.proxy.v3.AbstractTest.container; import org.apache.olingo.fit.proxy.v3.staticservice.microsoft.test.odata.services.astoriadefaultservice. types.Customer; import org.apache.olingo.fit.proxy.v3.staticservice.microsoft.test.odata.services.astoriadefaultservice. @@ -43,168 +44,166 @@ import org.junit.Test; */ public class EntityCreateTestITCase extends AbstractTest { - @Test - @Ignore - public void create() { - final String sampleName = "sample customer from proxy"; - final Integer id = 100; + @Test + public void create() { + container.getCustomer().get(-10); + final String sampleName = "sample customer from proxy"; + final Integer id = 100; - getSampleCustomerProfile(id, sampleName, container); - container.flush(); + getSampleCustomerProfile(id, sampleName, container); + container.flush(); - Customer actual = readCustomer(container, id); - checkSampleCustomerProfile(actual, id, sampleName); + Customer actual = readCustomer(container, id); + checkSampleCustomerProfile(actual, id, sampleName); - container.getCustomer().delete(actual.getCustomerId()); - actual = container.getCustomer().get(id); - assertNull(actual); + container.getCustomer().delete(actual.getCustomerId()); + actual = container.getCustomer().get(id); + assertNull(actual); - entityContext.detachAll(); - actual = container.getCustomer().get(id); - assertNotNull(actual); + entityContext.detachAll(); + actual = container.getCustomer().get(id); + assertNotNull(actual); - container.getCustomer().delete(actual.getCustomerId()); - container.flush(); + container.getCustomer().delete(actual.getCustomerId()); + container.flush(); - actual = container.getCustomer().get(id); - assertNull(actual); + actual = container.getCustomer().get(id); + assertNull(actual); - entityContext.detachAll(); - actual = container.getCustomer().get(id); - assertNull(actual); - } + entityContext.detachAll(); + actual = container.getCustomer().get(id); + assertNull(actual); + } - @Test - @Ignore - public void createEmployee() { - final Integer id = 101; + @Test + @Ignore + public void createEmployee() { + final Integer id = 101; - final Employee employee = container.getPerson().newEmployee(); - employee.setPersonId(id); - employee.setName("sample employee from proxy"); - employee.setManagersPersonId(-9918); - employee.setSalary(2147483647); - employee.setTitle("CEO"); + final Employee employee = container.getPerson().newEmployee(); + employee.setPersonId(id); + employee.setName("sample employee from proxy"); + employee.setManagersPersonId(-9918); + employee.setSalary(2147483647); + employee.setTitle("CEO"); - container.flush(); + container.flush(); - Employee actual = container.getPerson().get(id, Employee.class); - assertNotNull(actual); - assertEquals(id, actual.getPersonId()); + Employee actual = container.getPerson().get(id, Employee.class); + assertNotNull(actual); + assertEquals(id, actual.getPersonId()); - entityContext.detachAll(); - actual = container.getPerson().get(id, Employee.class); - assertNotNull(actual); + entityContext.detachAll(); + actual = container.getPerson().get(id, Employee.class); + assertNotNull(actual); - container.getPerson().delete(actual.getPersonId()); - container.flush(); + container.getPerson().delete(actual.getPersonId()); + container.flush(); - actual = container.getPerson().get(id, Employee.class); - assertNull(actual); + actual = container.getPerson().get(id, Employee.class); + assertNull(actual); - entityContext.detachAll(); - actual = container.getPerson().get(id, Employee.class); - assertNull(actual); - } + entityContext.detachAll(); + actual = container.getPerson().get(id, Employee.class); + assertNull(actual); + } - @Test - @Ignore - public void createWithNavigation() { - final String sampleName = "sample customer from proxy with navigation"; - final Integer id = 101; + @Test + public void createWithNavigation() { + final String sampleName = "sample customer from proxy with navigation"; + final Integer id = 101; - final Customer original = getSampleCustomerProfile(id, sampleName, container); - original.setInfo(container.getCustomerInfo().get(16)); - container.flush(); + final Customer original = getSampleCustomerProfile(id, sampleName, container); + original.setInfo(container.getCustomerInfo().get(16)); + container.flush(); - Customer actual = readCustomer(container, id); - checkSampleCustomerProfile(actual, id, sampleName); - assertEquals(Integer.valueOf(16), actual.getInfo().getCustomerInfoId()); + Customer actual = readCustomer(container, id); + checkSampleCustomerProfile(actual, id, sampleName); + assertEquals(Integer.valueOf(16), actual.getInfo().getCustomerInfoId()); - container.getCustomer().delete(actual.getCustomerId()); - container.flush(); + container.getCustomer().delete(actual.getCustomerId()); + container.flush(); - actual = container.getCustomer().get(id); - assertNull(actual); - } + actual = container.getCustomer().get(id); + assertNull(actual); + } - @Test - @Ignore - public void createWithBackNavigation() { - final String sampleName = "sample customer from proxy with back navigation"; - final Integer id = 102; + @Test + @Ignore + public void createWithBackNavigation() { + final String sampleName = "sample customer from proxy with back navigation"; + final Integer id = 102; - Order order = container.getOrder().newOrder(); - order.setCustomerId(id); - order.setOrderId(id); // same id ... + Order order = container.getOrder().newOrder(); + order.setCustomerId(id); + order.setOrderId(id); // same id ... - final Customer customer = getSampleCustomerProfile(id, sampleName, container); + final Customer customer = getSampleCustomerProfile(id, sampleName, container); - final OrderCollection orders = container.getOrder().newOrderCollection(); - orders.add(order); + final OrderCollection orders = container.getOrder().newOrderCollection(); + orders.add(order); - customer.setOrders(orders); - order.setCustomer(customer); - container.flush(); + customer.setOrders(orders); + order.setCustomer(customer); + container.flush(); - assertEquals(id, order.getOrderId()); - assertEquals(id, order.getCustomerId()); + assertEquals(id, order.getOrderId()); + assertEquals(id, order.getCustomerId()); - Customer actual = readCustomer(container, id); - checkSampleCustomerProfile(actual, id, sampleName); + Customer actual = readCustomer(container, id); + checkSampleCustomerProfile(actual, id, sampleName); - assertEquals(1, actual.getOrders().size()); - assertEquals(id, actual.getOrders().iterator().next().getOrderId()); - assertEquals(id, actual.getOrders().iterator().next().getCustomerId()); + assertEquals(1, actual.getOrders().size()); + assertEquals(id, actual.getOrders().iterator().next().getOrderId()); + assertEquals(id, actual.getOrders().iterator().next().getCustomerId()); - order = container.getOrder().get(id); - assertNotNull(order); - assertEquals(id, order.getCustomer().getCustomerId()); + order = container.getOrder().get(id); + assertNotNull(order); + assertEquals(id, order.getCustomer().getCustomerId()); - container.getOrder().delete(actual.getOrders()); - container.flush(); + container.getOrder().delete(actual.getOrders()); + container.flush(); - order = container.getOrder().get(id); - assertNull(order); + order = container.getOrder().get(id); + assertNull(order); - actual = readCustomer(container, id); - assertTrue(actual.getOrders().isEmpty()); + actual = readCustomer(container, id); + assertTrue(actual.getOrders().isEmpty()); - container.getCustomer().delete(actual.getCustomerId()); - container.flush(); + container.getCustomer().delete(actual.getCustomerId()); + container.flush(); - actual = container.getCustomer().get(id); - assertNull(actual); - } + actual = container.getCustomer().get(id); + assertNull(actual); + } - @Test - @Ignore - public void multiKey() { - Message message = container.getMessage().newMessage(); - message.setMessageId(100); - message.setFromUsername("fromusername"); - message.setToUsername("myusername"); - message.setIsRead(false); - message.setSubject("test message"); - message.setBody("test"); + @Test + public void multiKey() { + Message message = container.getMessage().newMessage(); + message.setMessageId(100); + message.setFromUsername("fromusername"); + message.setToUsername("myusername"); + message.setIsRead(false); + message.setSubject("test message"); + message.setBody("test"); - container.flush(); + container.flush(); - MessageKey key = new MessageKey(); - key.setFromUsername("fromusername"); - key.setMessageId(100); + MessageKey key = new MessageKey(); + key.setFromUsername("fromusername"); + key.setMessageId(100); - message = container.getMessage().get(key); - assertNotNull(message); - assertEquals(Integer.valueOf(100), message.getMessageId()); - assertEquals("fromusername", message.getFromUsername()); - assertEquals("myusername", message.getToUsername()); - assertEquals("test message", message.getSubject()); - assertEquals("test", message.getBody()); + message = container.getMessage().get(key); + assertNotNull(message); + assertEquals(Integer.valueOf(100), message.getMessageId()); + assertEquals("fromusername", message.getFromUsername()); + assertEquals("myusername", message.getToUsername()); + assertEquals("test message", message.getSubject()); + assertEquals("test", message.getBody()); - container.getMessage().delete(key); - container.flush(); + container.getMessage().delete(key); + container.flush(); - assertNull(container.getMessage().get(key)); - } + assertNull(container.getMessage().get(key)); + } } diff --git a/fit/src/test/java/org/apache/olingo/fit/proxy/v4/AuthEntityRetrieveTestITCase.java b/fit/src/test/java/org/apache/olingo/fit/proxy/v4/AuthEntityRetrieveTestITCase.java index 973449ebe..bafddad63 100644 --- a/fit/src/test/java/org/apache/olingo/fit/proxy/v4/AuthEntityRetrieveTestITCase.java +++ b/fit/src/test/java/org/apache/olingo/fit/proxy/v4/AuthEntityRetrieveTestITCase.java @@ -18,31 +18,29 @@ */ package org.apache.olingo.fit.proxy.v4; -import org.apache.olingo.client.core.http.BasicAuthHttpClientFactory; -import org.apache.olingo.client.core.http.DefaultHttpClientFactory; -import org.apache.olingo.ext.proxy.EntityContainerFactory; -import org.apache.olingo.fit.proxy.v4.staticservice.microsoft.test.odata.services.odatawcfservice.InMemoryEntities; import static org.junit.Assert.assertNotNull; import org.junit.AfterClass; import org.junit.BeforeClass; +import org.apache.olingo.client.core.http.BasicAuthHttpClientFactory; +import org.apache.olingo.ext.proxy.EntityContainerFactory; +import org.apache.olingo.fit.proxy.v4.staticservice.microsoft.test.odata.services.odatawcfservice.InMemoryEntities; + public class AuthEntityRetrieveTestITCase extends EntityRetrieveTestITCase { - @BeforeClass - public static void enableBasicAuth() { - containerFactory.getConfiguration(). - setHttpClientFactory(new BasicAuthHttpClientFactory("odatajclient", "odatajclient")); - } - - @AfterClass - public static void disableBasicAuth() { - containerFactory.getConfiguration().setHttpClientFactory(new DefaultHttpClientFactory()); - } - @BeforeClass public static void setupContaner() { containerFactory = EntityContainerFactory.getV3(testAuthServiceRootURL); + containerFactory.getConfiguration(). + setHttpClientFactory(new BasicAuthHttpClientFactory("odatajclient", "odatajclient")); + container = containerFactory.getEntityContainer(InMemoryEntities.class); + assertNotNull(container); + } + + @AfterClass + public static void disableBasicAuth() { + containerFactory = EntityContainerFactory.getV3(testStaticServiceRootURL); container = containerFactory.getEntityContainer(InMemoryEntities.class); assertNotNull(container); } diff --git a/fit/src/test/java/org/apache/olingo/fit/v3/EntityCreateTestITCase.java b/fit/src/test/java/org/apache/olingo/fit/v3/EntityCreateTestITCase.java index cc975218f..db26eee49 100644 --- a/fit/src/test/java/org/apache/olingo/fit/v3/EntityCreateTestITCase.java +++ b/fit/src/test/java/org/apache/olingo/fit/v3/EntityCreateTestITCase.java @@ -261,7 +261,7 @@ public class EntityCreateTestITCase extends AbstractTestITCase { createReq.setPrefer(client.newPreferences().returnContent()); try { - final ODataEntityCreateResponse createRes = createReq.execute(); + final ODataEntityCreateResponse createRes = createReq.execute(); assertEquals(201, createRes.getStatusCode()); } catch (Exception e) { fail(e.getMessage()); diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/uri/URIUtils.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/uri/URIUtils.java index 0e1d029c1..017041b2e 100644 --- a/lib/client-core/src/main/java/org/apache/olingo/client/core/uri/URIUtils.java +++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/uri/URIUtils.java @@ -407,8 +407,20 @@ public final class URIUtils { public static HttpEntity buildInputStreamEntity(final CommonODataClient client, final InputStream input) { HttpEntity entity; + + // -------------------------- + // Check just required by batch requests since their ansynchronous entity specification mechanism + // -------------------------- + boolean contentAvailable; + try { + contentAvailable = input.available()>0; + } catch (IOException ex) { + contentAvailable = false; + } + // -------------------------- + boolean repeatableRequired = shouldUseRepeatableHttpBodyEntry(client); - if (!repeatableRequired) { + if (!contentAvailable || !repeatableRequired) { entity = new InputStreamEntity(input, -1); } else { byte[] bytes = new byte[0];