Author: cschneider
Date: Thu Jul 16 13:53:29 2015
New Revision: 1691404
URL: http://svn.apache.org/r1691404
Log:
[ARIES-1346] Itest for programmatical coordination
Added:
aries/trunk/jpa/itests/jpa-container-blueprint-testbundle/src/main/java/org/apache/aries/jpa/container/itest/bundle/blueprint/impl/CarLifeCycle.java
Modified:
aries/trunk/jpa/itests/jpa-container-blueprint-testbundle/pom.xml
aries/trunk/jpa/itests/jpa-container-blueprint-testbundle/src/main/resources/OSGI-INF/blueprint/config.xml
aries/trunk/jpa/itests/jpa-container-itest/src/test/java/org/apache/aries/jpa/blueprint/aries/itest/BlueprintTest.java
Modified: aries/trunk/jpa/itests/jpa-container-blueprint-testbundle/pom.xml
URL:
http://svn.apache.org/viewvc/aries/trunk/jpa/itests/jpa-container-blueprint-testbundle/pom.xml?rev=1691404&r1=1691403&r2=1691404&view=diff
==============================================================================
--- aries/trunk/jpa/itests/jpa-container-blueprint-testbundle/pom.xml (original)
+++ aries/trunk/jpa/itests/jpa-container-blueprint-testbundle/pom.xml Thu Jul
16 13:53:29 2015
@@ -16,6 +16,11 @@
<dependencies>
<dependency>
+ <groupId>org.osgi</groupId>
+ <artifactId>org.osgi.compendium</artifactId>
+ <version>4.3.1</version>
+ </dependency>
+ <dependency>
<groupId>org.hibernate.javax.persistence</groupId>
<artifactId>hibernate-jpa-2.0-api</artifactId>
<version>1.0.1.Final</version>
Added:
aries/trunk/jpa/itests/jpa-container-blueprint-testbundle/src/main/java/org/apache/aries/jpa/container/itest/bundle/blueprint/impl/CarLifeCycle.java
URL:
http://svn.apache.org/viewvc/aries/trunk/jpa/itests/jpa-container-blueprint-testbundle/src/main/java/org/apache/aries/jpa/container/itest/bundle/blueprint/impl/CarLifeCycle.java?rev=1691404&view=auto
==============================================================================
---
aries/trunk/jpa/itests/jpa-container-blueprint-testbundle/src/main/java/org/apache/aries/jpa/container/itest/bundle/blueprint/impl/CarLifeCycle.java
(added)
+++
aries/trunk/jpa/itests/jpa-container-blueprint-testbundle/src/main/java/org/apache/aries/jpa/container/itest/bundle/blueprint/impl/CarLifeCycle.java
Thu Jul 16 13:53:29 2015
@@ -0,0 +1,68 @@
+/* Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.aries.jpa.container.itest.bundle.blueprint.impl;
+
+import java.util.Collection;
+
+import org.apache.aries.jpa.container.itest.entities.Car;
+import org.apache.aries.jpa.container.itest.entities.CarService;
+import org.osgi.service.coordinator.Coordinator;
+
+/**
+ * Programmatically uses a Coordination to do a series of calls with the
+ * same EntityManager
+ */
+public class CarLifeCycle implements Runnable {
+ CarService carService;
+ Coordinator coordinator;
+
+ @Override
+ public void run() {
+ Car car = new Car();
+ car.setNumberPlate("blue");
+ carService.addCar(car);
+
+ try {
+ readAndUpdate();
+ throw new IllegalStateException("This should not work with an
active coordination");
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+
+
+ coordinator.begin("jpa", 0);
+ readAndUpdate();
+ coordinator.pop().end();
+
+ carService.deleteCar("blue");
+ }
+
+ /**
+ * These operations only work if the EntityManager stays open
+ */
+ private void readAndUpdate() {
+ Collection<Car> cars = carService.getCars();
+ carService.updateCar(cars.iterator().next());
+ }
+
+ public void setCarService(CarService carService) {
+ this.carService = carService;
+ }
+
+ public void setCoordinator(Coordinator coordinator) {
+ this.coordinator = coordinator;
+ }
+}
Modified:
aries/trunk/jpa/itests/jpa-container-blueprint-testbundle/src/main/resources/OSGI-INF/blueprint/config.xml
URL:
http://svn.apache.org/viewvc/aries/trunk/jpa/itests/jpa-container-blueprint-testbundle/src/main/resources/OSGI-INF/blueprint/config.xml?rev=1691404&r1=1691403&r2=1691404&view=diff
==============================================================================
---
aries/trunk/jpa/itests/jpa-container-blueprint-testbundle/src/main/resources/OSGI-INF/blueprint/config.xml
(original)
+++
aries/trunk/jpa/itests/jpa-container-blueprint-testbundle/src/main/resources/OSGI-INF/blueprint/config.xml
Thu Jul 16 13:53:29 2015
@@ -1,8 +1,13 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
- xmlns:jpa="http://aries.apache.org/xmlns/jpan/v1.0.0"
xmlns:tx="http://aries.apache.org/xmlns/transactions/v1.2.0"
+ xmlns:ext="http://aries.apache.org/blueprint/xmlns/blueprint-ext/v1.0.0"
+ xmlns:jpa="http://aries.apache.org/xmlns/jpan/v1.0.0"
+ xmlns:tx="http://aries.apache.org/xmlns/transactions/v1.2.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://www.osgi.org/xmlns/blueprint/v1.0.0">
+ xsi:schemaLocation="
+ http://www.osgi.org/xmlns/blueprint/v1.0.0
https://osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd
+ http://aries.apache.org/blueprint/xmlns/blueprint-ext/v1.0.0
http://aries.apache.org/schemas/blueprint-ext/blueprint-ext.xsd
+ ">
<jpa:enable />
@@ -66,5 +71,17 @@
<tx:transaction method="*" value="Required" />
</bean>
+ <bean id="carLifeCycle"
class="org.apache.aries.jpa.container.itest.bundle.blueprint.impl.CarLifeCycle"
>
+ <property name="coordinator" ref="coordinator"/>
+ <property name="carService" ref="carServiceEm"/>
+ </bean>
+
+ <reference id="coordinator"
interface="org.osgi.service.coordinator.Coordinator" />
+
+ <service ref="carLifeCycle" interface="java.lang.Runnable" >
+ <service-properties>
+ <entry key="type" value="carCoordinated"/>
+ </service-properties>
+ </service>
</blueprint>
Modified:
aries/trunk/jpa/itests/jpa-container-itest/src/test/java/org/apache/aries/jpa/blueprint/aries/itest/BlueprintTest.java
URL:
http://svn.apache.org/viewvc/aries/trunk/jpa/itests/jpa-container-itest/src/test/java/org/apache/aries/jpa/blueprint/aries/itest/BlueprintTest.java?rev=1691404&r1=1691403&r2=1691404&view=diff
==============================================================================
---
aries/trunk/jpa/itests/jpa-container-itest/src/test/java/org/apache/aries/jpa/blueprint/aries/itest/BlueprintTest.java
(original)
+++
aries/trunk/jpa/itests/jpa-container-itest/src/test/java/org/apache/aries/jpa/blueprint/aries/itest/BlueprintTest.java
Thu Jul 16 13:53:29 2015
@@ -75,6 +75,12 @@ public class BlueprintTest extends Abstr
public void testSupplierAddQuery() throws Exception {
carLifecycle(getCarService("supplier"));
}
+
+ @Test
+ public void testCoordinationLifecycle() {
+ Runnable carLifeCycle = getService(Runnable.class,
"(type=carCoordinated)");
+ carLifeCycle.run();
+ }
private CarService getCarService(String type) {
return getService(CarService.class, "(type=" + type + ")");