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 4 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
7 changes: 7 additions & 0 deletions tcks/apis/connector-whitebox/whitebox/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<jakarta.transaction-api.version>2.0.2-SNAPSHOT</jakarta.transaction-api.version>
</properties>

<dependencies>
Expand All @@ -24,6 +25,12 @@
<artifactId>jakarta.authentication-api</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>jakarta.transaction</groupId>
<artifactId>jakarta.transaction-api</artifactId>
<version>${jakarta.transaction-api.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>jakarta.tck</groupId>
<artifactId>common</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2007, 2020 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2007, 2025 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
Expand Down Expand Up @@ -36,6 +36,7 @@ public class ConnectorStatus implements Log {
private Vector statelog = new Vector();

private boolean logFlag = false;
private volatile boolean supportReadOnly = true;

/**
* Singleton constructor
Expand Down Expand Up @@ -107,4 +108,17 @@ public void setLogFlag(boolean b) {
logFlag = b;
}

/**
* Retrieves the readOnly support
*/
public boolean isSupportReadOnly() {
return supportReadOnly;
}

/**
* Sets the readOnly support to true/false
*/
public void setSupportReadOnly(boolean supportReadOnly) {
this.supportReadOnly = supportReadOnly;
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2007, 2020 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2007, 2025 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
Expand Down Expand Up @@ -67,6 +67,14 @@ public void closeRM() {
association.clear();
}

public void setReadOnly(Xid xid) throws XAException {
sanityCheck(xid, XAResource.TMNOFLAGS, "setReadOnly");

TSXaTransaction txn = new TSXaTransaction(xid);
txn.setReadOnly(true);
association.put(xid, txn);
}

/**
* Starts the new Global Transaction branch. transaction can be started in three ways.
*
Expand All @@ -89,7 +97,9 @@ public void start(Xid xid, int flags, TSConnection con) throws XAException {
sanityCheck(xid, flags, "start");

if (flags == XAResource.TMNOFLAGS) {
TSXaTransaction txn = new TSXaTransaction(xid);
TSXaTransaction txn = (TSXaTransaction) association.get(xid);
if (txn == null)
txn = new TSXaTransaction(xid);
txn.setStatus(TSXaTransaction.STARTED);
if (con != null)
txn.addConnection(con);
Expand Down Expand Up @@ -228,6 +238,28 @@ int getTransactionStatus(TSConnection con) {
return TSXaTransaction.NOTRANSACTION;
}

/**
* Get the Transaction read-only value of a Connection.
*
* @param con Connection involved.
*/
boolean isTransactionReadOnly(TSConnection con) {
Enumeration e = association.keys();
while (e.hasMoreElements()) {
Xid id = (Xid) e.nextElement();
TSXaTransaction txn = (TSXaTransaction) association.get(id);
Hashtable connections = txn.getConnections();
Enumeration e1 = connections.keys();
while (e1.hasMoreElements()) {
TSConnection temp = (TSConnection) e1.nextElement();
if (con == temp) {
return txn.isReadOnly();
}
}
}
return false;
}

/**
* Reads a particular key in a distributed transaction.
*
Expand Down Expand Up @@ -257,6 +289,15 @@ DataElement read(String key, TSConnection con) throws TSEISException {
* @throws XAExcpetion In case of an invalid XA protocol.
*/
private void sanityCheck(Xid xid, int flags, String operation) throws XAException {
if ((operation != null) && (operation.equals("setReadOnly"))) {
if (!(flags == XAResource.TMNOFLAGS)) {
throw new XAException(XAException.XAER_INVAL);
}

if (association.containsKey(xid)) {
throw new XAException(XAException.XAER_DUPID);
}
}
// Sanity checks for the xa_start operation.
if ((operation != null) && (operation.equals("start"))) {

Expand All @@ -266,7 +307,8 @@ private void sanityCheck(Xid xid, int flags, String operation) throws XAExceptio

// For TMNOFLAGS xid should not be known to RM.
if (flags == XAResource.TMNOFLAGS) {
if (association.containsKey(xid)) {
TSXaTransaction txn = (TSXaTransaction) association.get(xid);
if (txn != null && txn.getStatus() != TSXaTransaction.NOTRANSACTION) {
throw new XAException(XAException.XAER_DUPID);
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2007, 2020 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2007, 2025 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
Expand Down Expand Up @@ -60,6 +60,9 @@ public class TSXaTransaction {
/** Field storing the status values **/
private int status = 0;

/** Field storing the read-only value **/
private boolean readOnly = false;

/** Connections involved in one transaction branch. Specifications doesnt **/
/** stop from having more than one connection in global transaction **/
private Hashtable connections = new Hashtable();
Expand Down Expand Up @@ -112,6 +115,24 @@ public int getStatus() {
return this.status;
}

/**
* Get the read-only value of the transaction.
*
* @return Read-only value of the transaction.
*/
public boolean isReadOnly() {
return readOnly;
}

/**
* Sets the read-only value of the transaction.
*
* @param readOnly of the transaction
*/
public void setReadOnly(boolean readOnly) {
this.readOnly = readOnly;
}

/**
* Prepare the transaction.
*
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2007, 2020 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2007, 2025 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
Expand Down Expand Up @@ -160,6 +160,9 @@ public String readValue(String key, TSConnection con) throws TSEISException {
}

public void insert(String key, String value, TSConnection con) throws TSEISException {
if (getResourceManager().isTransactionReadOnly(con)) {
throw new TSEISException("Read only transaction");
}

boolean datapresent = false;

Expand Down Expand Up @@ -187,6 +190,9 @@ public void insert(String key, String value, TSConnection con) throws TSEISExcep
}

public void update(String key, String value, TSConnection con) throws TSEISException {
if (getResourceManager().isTransactionReadOnly(con)) {
throw new TSEISException("Read only transaction");
}
DataElement de = read(key, con);
de.updateVersion();
de.setValue(value);
Expand All @@ -206,6 +212,9 @@ public void update(String key, String value, TSConnection con) throws TSEISExcep
}

public void delete(String key, TSConnection con) throws TSEISException {
if (getResourceManager().isTransactionReadOnly(con)) {
throw new TSEISException("Read only transaction");
}
DataElement de = read(key, con);
if ((getResourceManager().getTransactionStatus(con) == TSXaTransaction.NOTRANSACTION) && con.getAutoCommit()) {
System.out.println("TSeis.delete.permtable");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2007, 2020 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2007, 2025 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
Expand Down Expand Up @@ -27,8 +27,9 @@
import javax.transaction.xa.Xid;

import com.sun.ts.tests.common.connector.util.ConnectorStatus;
import jakarta.transaction.xa.ExtendedXAResource;

public class XAResourceImpl implements XAResource {
public class XAResourceImpl implements ExtendedXAResource {

private TSManagedConnection mc;

Expand All @@ -52,6 +53,24 @@ private void handleResourceException(Exception ex) throws XAException {
throw xae;
}

@Override
public boolean setReadOnly(Xid xid) throws XAException {
try {
ConnectorStatus.getConnectorStatus().logAPI("ExtendedXAResource.setReadOnly", "", "");
if (ConnectorStatus.getConnectorStatus().isSupportReadOnly()) {
TSeis.getTSeis().getResourceManager().setReadOnly(xid);
return true;
} else {
return false;
}
} catch (XAException xe) {
throw xe;
} catch (Exception ex) {
handleResourceException(ex);
return false;
}
}

public void commit(Xid xid, boolean onePhase) throws XAException {
try {
System.out.println("XAResourceImpl.commit");
Expand Down
10 changes: 10 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 Expand Up @@ -94,6 +96,14 @@
<groupId>jakarta.tck</groupId>
<artifactId>common</artifactId>
</dependency>
<dependency>
<groupId>jakarta.tck</groupId>
<artifactId>whitebox</artifactId>
</dependency>
<dependency>
<groupId>jakarta.tck</groupId>
<artifactId>connector</artifactId>
</dependency>

<dependency>
<groupId>jakarta.tck.arquillian</groupId>
Expand Down
Loading
Loading