-
Notifications
You must be signed in to change notification settings - Fork 144
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #24851 from escay/issue_24849
Fixes issue #24849 make relevant methods synchronized in LocalTxConnectionEventListener
- Loading branch information
Showing
4 changed files
with
165 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
87 changes: 87 additions & 0 deletions
87
...rc/test/java/com/sun/enterprise/resource/listener/LocalTxConnectionEventListenerTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
/* | ||
* Copyright (c) 2024 Contributors to the Eclipse Foundation | ||
* | ||
* 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 | ||
*/ | ||
|
||
package com.sun.enterprise.resource.listener; | ||
|
||
import static org.easymock.EasyMock.createNiceMock; | ||
import static org.easymock.EasyMock.replay; | ||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertNull; | ||
|
||
import java.util.Map; | ||
|
||
import org.glassfish.api.naming.SimpleJndiName; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import com.sun.appserv.connectors.internal.api.PoolingException; | ||
import com.sun.enterprise.connectors.ConnectorRuntime; | ||
import com.sun.enterprise.resource.ResourceHandle; | ||
import com.sun.enterprise.resource.ResourceSpec; | ||
|
||
import jakarta.resource.ResourceException; | ||
import jakarta.resource.spi.ManagedConnection; | ||
|
||
public class LocalTxConnectionEventListenerTest { | ||
|
||
@BeforeEach | ||
public void setup() throws PoolingException, ResourceException { | ||
// Make sure ConnectorRuntime singleton is initialized | ||
new ConnectorRuntime(); | ||
} | ||
|
||
@Test | ||
public void associateHandleTest() throws ResourceException { | ||
ResourceHandle mainResourceHandle = createResourceHandle(1); | ||
LocalTxConnectionEventListener localTxConnectionEventListener = new LocalTxConnectionEventListener(mainResourceHandle); | ||
|
||
// Associate a new handle association | ||
ResourceHandle associatedResourceHandle = createResourceHandle(2); | ||
final Object userHandle = new Object(); | ||
localTxConnectionEventListener.associateHandle(userHandle, associatedResourceHandle); | ||
|
||
// Remove the new handle association | ||
ResourceHandle removeAssociation = localTxConnectionEventListener.removeAssociation(userHandle); | ||
assertEquals(associatedResourceHandle, removeAssociation); | ||
|
||
// Check the remove did work in the previous call | ||
removeAssociation = localTxConnectionEventListener.removeAssociation(userHandle); | ||
assertNull(removeAssociation); | ||
} | ||
|
||
@Test | ||
public void getAssociatedHandlesAndClearMapTest() throws ResourceException { | ||
ResourceHandle mainResourceHandle = createResourceHandle(1); | ||
LocalTxConnectionEventListener localTxConnectionEventListener = new LocalTxConnectionEventListener(mainResourceHandle); | ||
|
||
localTxConnectionEventListener.associateHandle(new Object(), createResourceHandle(2)); | ||
localTxConnectionEventListener.associateHandle(new Object(), createResourceHandle(3)); | ||
|
||
// Check the clone works | ||
Map<Object, ResourceHandle> associatedHandlesAndClearMap = localTxConnectionEventListener.getAssociatedHandlesAndClearMap(); | ||
assertEquals(2, associatedHandlesAndClearMap.size()); | ||
|
||
// Check the clear did work in the previous call | ||
associatedHandlesAndClearMap = localTxConnectionEventListener.getAssociatedHandlesAndClearMap(); | ||
assertEquals(0, associatedHandlesAndClearMap.size()); | ||
} | ||
|
||
private ResourceHandle createResourceHandle(int i) throws ResourceException { | ||
ManagedConnection managedConnection = createNiceMock(ManagedConnection.class); | ||
replay(); | ||
return new ResourceHandle(managedConnection, new ResourceSpec(new SimpleJndiName("testResource" + i), 0), null, null); | ||
} | ||
} |