Skip to content

TCK test for Jakarta Transactions #220 #2163

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions tcks/apis/transactions/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<jakarta.transaction-api.version>2.0.2-SNAPSHOT</jakarta.transaction-api.version>
</properties>

<dependencyManagement>
Expand All @@ -54,6 +55,7 @@
<dependency>
<groupId>jakarta.transaction</groupId>
<artifactId>jakarta.transaction-api</artifactId>
<version>${jakarta.transaction-api.version}</version>
</dependency>
<dependency>
<groupId>jakarta.enterprise</groupId>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,211 @@
/*
* Copyright (c) 2007, 2020 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0, which is available at
* http://www.eclipse.org/legal/epl-2.0.
*
* This Source Code may also be made available under the following Secondary
* Licenses when the conditions for such availability set forth in the
* Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
* version 2 with the GNU Classpath Exception, which is available at
* https://www.gnu.org/software/classpath/license.html.
*
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
*/

/*
* @(#)UserSetTransactionTimeoutClient.java 1.21 03/05/16
*/

package com.sun.ts.tests.jta.ee.usertransaction.setreadonly;

import java.io.Serializable;
import java.util.Properties;

import com.sun.ts.lib.harness.ServiceEETest;
import com.sun.ts.tests.jta.ee.common.Transact;
import jakarta.transaction.RollbackException;
import jakarta.transaction.Status;
import jakarta.transaction.SystemException;
import jakarta.transaction.UserTransaction;

/**
* The UserSetReadOnlyClient class tests setReadOnly() method of UserTransaction interface using
* Sun's J2EE Reference Implementation.
*/

public class UserSetReadOnlyClient extends ServiceEETest implements Serializable {
private static final String testName = "jta.ee.usertransaction.setreadonly";

private UserTransaction userTransaction = null;

public void setup(String[] args, Properties p) throws Exception {
try {
// Initializes the Environment
Transact.init();
logTrace("Test environment initialized");

// Gets the User Transaction
userTransaction = (UserTransaction) Transact.nctx.lookup("java:comp/UserTransaction");
logMsg("User Transaction object is Obtained");

if (userTransaction == null) {
logErr("Unable to get User Transaction" + " Instance : Could not proceed with" + " tests");
throw new Exception("couldnt proceed further");
} else if (userTransaction.getStatus() == Status.STATUS_ACTIVE) {
userTransaction.rollback();
}
} catch (Exception exception) {
logErr("Setup Failed!");
logTrace("Unable to get User Transaction Instance :" + " Could not proceed with tests");
throw new Exception("Setup Failed", exception);
}
}// End of setup

public static void main(String args[]) {
UserSetReadOnlyClient userSetTransTout = new UserSetReadOnlyClient();
com.sun.ts.lib.harness.Status s = userSetTransTout.run(args, System.out, System.err);
s.exit();

} // End of main

// Beginning of TestCases

/**
* @testName: testUserSetReadOnly001
* @test_Strategy: Before starting the User Transaction set the transaction time out as 10 seconds.Allow the thread to
* sleep for 30 seconds then call commit() User Transaction.
*/
public void testUserSetReadOnly001() throws Exception {
boolean pass1 = false;
boolean pass2 = false;
boolean pass3 = false;

try {
if (!userTransaction.isReadOnly()) {
pass1 = true;
}

// Sets the readOnly value for the current transaction
userTransaction.setReadOnly(true);

// Starts a Global Transaction & associates with
// Current Thread.
userTransaction.begin();
logMsg("UserTransaction Started");

if (userTransaction.isReadOnly()) {
logMsg("UserTransaction readOnly is true");
pass2 = true;
}

// Commits the transaction.
userTransaction.commit();

if (!userTransaction.isReadOnly()) {
pass3 = true;
}

if (pass1 && pass2 && pass3) {
logMsg( "testUserSetReadOnly001 Passed" );
} else if (!pass1) {
throw new Exception("UserTransaction isReadOnly expected false on non active transaction");
} else if (!pass2) {
throw new Exception("UserTransaction isReadOnly expected true on new active transaction after setReadOnly");
} else {
throw new Exception("UserTransaction isReadOnly expected false on non active transaction");
}
} catch (Exception exception) {
logErr("Exception " + exception.toString() + " was caught");
throw new Exception("Exception was not thrown as" + " Expected in commit()", exception);
}

}// End of testUserSetReadOnly001

/**
* @testName: testUserSetReadOnly002
* @test_Strategy: Before starting the User Transaction set the transaction time out as 10 seconds.Allow the thread to
* sleep for 5 seconds then Call commit() User Transaction.Check the status of the User Transaction.
*/

public void testUserSetReadOnly002() throws Exception {
boolean pass1 = false;
boolean pass2 = false;
boolean pass3 = false;

try {
if (!userTransaction.isReadOnly()) {
pass1 = true;
}
// Starts a Global Transaction & associates with
// Current Thread.
userTransaction.begin();
logMsg("UserTransaction Started");

// Sets the readOnly value for the current transaction
userTransaction.setReadOnly(true);

if (!userTransaction.isReadOnly()) {
pass2 = true;
}

// Commits the transaction.
userTransaction.commit();

if (!userTransaction.isReadOnly()) {
pass3 = true;
}

if (pass1 && pass2 && pass3) {
logMsg( "testUserSetReadOnly002 Passed" );
} else if (!pass1) {
throw new Exception("UserTransaction isReadOnly expected false on non active transaction");
} else if (!pass2) {
throw new Exception("UserTransaction isReadOnly expected false on existing active transaction after setReadOnly");
} else {
throw new Exception("UserTransaction isReadOnly expected false on non active transaction");
}
} catch (SystemException system) {
logErr("Exception " + system.toString() + " was caught");
throw new Exception("UnExpected Exception was caught:" + " Failed", system);
} catch (Exception exception) {
logErr("Exception " + exception.toString() + " was caught");
throw new Exception("UnExpected Exception was caught:" + " Failed", exception);
}

}// End of testUserSetReadOnly002

public void cleanup() throws Exception {
try {
// Removing noisy stack trace.
if (userTransaction.getStatus() == Status.STATUS_ACTIVE) {
// Frees Current Thread, from Transaction
Transact.free();
try {
userTransaction.rollback();
} catch (Exception exception) {
throw new Exception(exception.getCause());
}
int retries = 1;
while ((userTransaction.getStatus() != Status.STATUS_NO_TRANSACTION) && (retries <= 5)) {
logMsg("cleanup(): retry # " + retries);
try {
Thread.sleep(1000);
} catch (Exception e) {
throw new Exception(e.getCause());
}
retries++;
}
logMsg("Cleanup ok;");
} else {
logMsg("CleanUp not required as Transaction is not in Active state.");
}
} catch (Exception exception) {
logErr("Cleanup Failed", exception);
logTrace("Could not clean the environment");
}

}// End of cleanup

}// End of UserSetReadOnlyClient
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
package com.sun.ts.tests.jta.ee.usertransaction.setreadonly;

import java.lang.System.Logger;
import java.net.URL;

import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestInfo;
import org.junit.jupiter.api.extension.ExtendWith;

import org.jboss.arquillian.container.test.api.Deployment;
import org.jboss.arquillian.container.test.api.OverProtocol;
import org.jboss.arquillian.container.test.api.TargetsContainer;
import org.jboss.arquillian.junit5.ArquillianExtension;
import org.jboss.arquillian.test.api.ArquillianResource;
import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.shrinkwrap.api.asset.StringAsset;
import org.jboss.shrinkwrap.api.spec.EnterpriseArchive;
import org.jboss.shrinkwrap.api.spec.JavaArchive;

import tck.arquillian.porting.lib.spi.TestArchiveProcessor;
import tck.arquillian.protocol.common.TargetVehicle;

@ExtendWith(ArquillianExtension.class)
@Tag("jta")
@Tag("platform")
@Tag("tck-appclient")

public class UserSetReadOnlyClientEjbTest
extends UserSetReadOnlyClient {
static final String VEHICLE_ARCHIVE = "setreadonly_ejb_vehicle";

private static String packagePath = UserSetReadOnlyClientEjbTest.class.getPackageName().replace( ".", "/");

private static final Logger logger = System.getLogger( UserSetReadOnlyClientEjbTest.class.getName());

@BeforeEach
void logStartTest(TestInfo testInfo) {
logger.log(Logger.Level.INFO, "STARTING TEST : " + testInfo.getDisplayName());
}

@AfterEach
void logFinishTest(TestInfo testInfo) {
logger.log(Logger.Level.INFO, "FINISHED TEST : " + testInfo.getDisplayName());
}

@Override
@AfterEach
public void cleanup() {
logger.log(Logger.Level.INFO, "cleanup ok");
}

@TargetsContainer("tck-appclient")
@OverProtocol("appclient")
@Deployment(name = VEHICLE_ARCHIVE, order = 2)
public static EnterpriseArchive createDeploymentVehicle(@ArquillianResource TestArchiveProcessor archiveProcessor) {
JavaArchive setreadonly_ejb_vehicle_client = ShrinkWrap.create(JavaArchive.class,
"setreadonly_ejb_vehicle_client.jar");
setreadonly_ejb_vehicle_client.addClasses(com.sun.ts.tests.common.vehicle.VehicleRunnable.class,
com.sun.ts.tests.common.vehicle.VehicleRunnerFactory.class, com.sun.ts.tests.common.vehicle.ejb.EJBVehicleRemote.class,
Fault.class, com.sun.ts.tests.common.vehicle.EmptyVehicleRunner.class,
com.sun.ts.tests.common.vehicle.ejb.EJBVehicleRunner.class, com.sun.ts.lib.harness.EETest.class,
com.sun.ts.lib.harness.ServiceEETest.class, SetupException.class,
com.sun.ts.tests.common.vehicle.VehicleClient.class, com.sun.ts.tests.jta.ee.common.Transact.class,
com.sun.ts.tests.jta.ee.common.TransactionStatus.class, com.sun.ts.tests.jta.ee.common.InvalidStatusException.class,
com.sun.ts.tests.jta.ee.common.InitFailedException.class, UserSetReadOnlyClient.class,
UserSetReadOnlyClientEjbTest.class);
// The application-client.xml descriptor
URL resURL = UserSetReadOnlyClientEjbTest.class.getClassLoader().getResource( packagePath + "/ejb_vehicle_client.xml");
if (resURL != null) {
setreadonly_ejb_vehicle_client.addAsManifestResource(resURL, "application-client.xml");
}
resURL = UserSetReadOnlyClientEjbTest.class.getClassLoader()
.getResource(packagePath + "/setreadonly_ejb_vehicle_client.jar.sun-application-client.xml");
if (resURL != null) {
setreadonly_ejb_vehicle_client.addAsManifestResource(resURL, "sun-application-client.xml");
}
setreadonly_ejb_vehicle_client.addAsManifestResource(
new StringAsset("Main-Class: " + UserSetReadOnlyClientEjbTest.class.getName() + "\n"), "MANIFEST.MF");
archiveProcessor.processClientArchive(setreadonly_ejb_vehicle_client, UserSetReadOnlyClientEjbTest.class,
resURL);

JavaArchive setreadonly_ejb_vehicle_ejb = ShrinkWrap.create(JavaArchive.class,
"setreadonly_ejb_vehicle_ejb.jar");
setreadonly_ejb_vehicle_ejb.addClasses(com.sun.ts.tests.common.vehicle.VehicleRunnerFactory.class,
Fault.class, com.sun.ts.tests.jta.ee.common.Transact.class,
com.sun.ts.tests.jta.ee.common.InvalidStatusException.class,
UserSetReadOnlyClient.class,
com.sun.ts.tests.common.vehicle.ejb.EJBVehicle.class, com.sun.ts.tests.jta.ee.common.InitFailedException.class,
com.sun.ts.tests.jta.ee.common.TransactionStatus.class, com.sun.ts.tests.common.vehicle.VehicleRunnable.class,
com.sun.ts.tests.common.vehicle.ejb.EJBVehicleRemote.class, com.sun.ts.lib.harness.EETest.class,
com.sun.ts.lib.harness.ServiceEETest.class, SetupException.class,
com.sun.ts.tests.common.vehicle.VehicleClient.class, UserSetReadOnlyClientEjbTest.class);
// The ejb-jar.xml descriptor
URL ejbResURL = UserSetReadOnlyClientEjbTest.class.getClassLoader().getResource( packagePath + "/ejb_vehicle_ejb.xml");
if (ejbResURL != null) {
setreadonly_ejb_vehicle_ejb.addAsManifestResource(ejbResURL, "ejb-jar.xml");
}
// The sun-ejb-jar.xml file
ejbResURL = UserSetReadOnlyClientEjbTest.class.getClassLoader()
.getResource(packagePath + "/setreadonly_ejb_vehicle_ejb.jar.sun-ejb-jar.xml");
if (ejbResURL != null) {
setreadonly_ejb_vehicle_ejb.addAsManifestResource(ejbResURL, "sun-ejb-jar.xml");
}
archiveProcessor.processEjbArchive( setreadonly_ejb_vehicle_ejb, UserSetReadOnlyClientEjbTest.class, ejbResURL);

EnterpriseArchive setreadonly_ejb_vehicle_ear = ShrinkWrap.create(EnterpriseArchive.class,
"setreadonly_ejb_vehicle.ear");
setreadonly_ejb_vehicle_ear.addAsModule(setreadonly_ejb_vehicle_ejb);
setreadonly_ejb_vehicle_ear.addAsModule(setreadonly_ejb_vehicle_client);

return setreadonly_ejb_vehicle_ear;
}

@Test
@Override
@TargetVehicle("ejb")
public void testUserSetReadOnly001() throws Exception {
super.testUserSetReadOnly001();
}

@Test
@Override
@TargetVehicle("ejb")
public void testUserSetReadOnly002() throws Exception {
super.testUserSetReadOnly002();
}

}
Loading
Loading