Skip to content

Commit

Permalink
try to fix transaction strategy
Browse files Browse the repository at this point in the history
  • Loading branch information
tandraschko committed Feb 20, 2024
1 parent 8bd220b commit 861c140
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 12 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* 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.deltaspike.data.test;

import jakarta.annotation.Priority;
import jakarta.enterprise.context.Dependent;
import jakarta.enterprise.inject.Alternative;
import jakarta.interceptor.Interceptor;
import org.apache.deltaspike.jpa.impl.transaction.ResourceLocalTransactionStrategy;

@Dependent
@Alternative
@Priority(Interceptor.Priority.APPLICATION + 1)
public class TestTransactionStrategy extends ResourceLocalTransactionStrategy
{

}
Original file line number Diff line number Diff line change
Expand Up @@ -18,25 +18,21 @@
*/
package org.apache.deltaspike.data.test.util;

import java.io.File;
import java.net.URL;

import org.apache.deltaspike.data.test.TestTransactionStrategy;
import org.apache.deltaspike.data.test.TransactionalTestCase;
import org.apache.deltaspike.data.test.domain.AuditedEntity;
import org.jboss.arquillian.container.test.spi.TestDeployment;
import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.shrinkwrap.api.asset.Asset;
import org.jboss.shrinkwrap.api.asset.EmptyAsset;
import org.jboss.shrinkwrap.api.asset.StringAsset;
import org.jboss.shrinkwrap.api.spec.EnterpriseArchive;
import org.jboss.shrinkwrap.api.spec.WebArchive;
import org.jboss.shrinkwrap.resolver.api.maven.Maven;

public abstract class TestDeployments {
import java.io.File;
import java.net.URL;

public static String DS_PROPERTIES_WITH_ENV_AWARE_TX_STRATEGY
= "globalAlternatives.org.apache.deltaspike.jpa.spi.transaction.TransactionStrategy="
+ "org.apache.deltaspike.jpa.impl.transaction.EnvironmentAwareTransactionStrategy";
public abstract class TestDeployments {

/**
* Create a basic deployment with dependencies, beans.xml and persistence descriptor.
Expand All @@ -60,13 +56,11 @@ public static WebArchive initDeployment(boolean addDefaultEntityManagerProducer,
WebArchive archive = ShrinkWrap
.create(WebArchive.class, "test.war")
// used by many tests, shouldn't interfere with others
.addClasses(TransactionalTestCase.class, TestData.class)
.addClasses(TransactionalTestCase.class, TestData.class, TestTransactionStrategy.class)
.addPackages(true, AuditedEntity.class.getPackage())
.addAsLibraries(getDeltaSpikeDataWithDependencies())
.addAsWebInfResource("test-persistence.xml", "classes/META-INF/persistence.xml")
.addAsWebInfResource(beansXmlAsset, "beans.xml")
.addAsWebInfResource(new StringAsset(DS_PROPERTIES_WITH_ENV_AWARE_TX_STRATEGY),
"classes/META-INF/apache-deltaspike.properties");
.addAsWebInfResource(beansXmlAsset, "beans.xml");

if (addDefaultEntityManagerProducer)
{
Expand Down

1 comment on commit 861c140

@shadogray
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I dont understand the idea:

  1. ResourceLocalTS is default strategy, so no need to override
  2. the persitence context is JPA - so this strategy will not work
    I was implementing the exact reverse (CMT), which worked on Wildfly (wildfly-build-managed)
    What shall I do?

Please sign in to comment.