-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
WFLY-850 Adding transaction timeout info to programmatic timer #6088
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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
47 changes: 47 additions & 0 deletions
47
...c/test/java/org/jboss/as/test/integration/ejb/timerservice/tx/timeout/AbstractTxBean.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,47 @@ | ||
/* | ||
* JBoss, Home of Professional Open Source | ||
* Copyright 2010, Red Hat Inc., and individual contributors as indicated | ||
* by the @authors tag. See the copyright.txt in the distribution for a | ||
* full listing of individual contributors. | ||
* | ||
* This is free software; you can redistribute it and/or modify it | ||
* under the terms of the GNU Lesser General Public License as | ||
* published by the Free Software Foundation; either version 2.1 of | ||
* the License, or (at your option) any later version. | ||
* | ||
* This software is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
* Lesser General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public | ||
* License along with this software; if not, write to the Free | ||
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA | ||
* 02110-1301 USA, or see the FSF site: http://www.fsf.org. | ||
*/ | ||
package org.jboss.as.test.integration.ejb.timerservice.tx.timeout; | ||
|
||
import javax.annotation.Resource; | ||
import javax.transaction.TransactionManager; | ||
|
||
import com.arjuna.ats.jta.transaction.Transaction; | ||
|
||
/** | ||
* @author Tomasz Adamski | ||
*/ | ||
public abstract class AbstractTxBean { | ||
|
||
@Resource(lookup = "java:jboss/TransactionManager") | ||
private TransactionManager transactionManager; | ||
|
||
private Transaction transaction; | ||
|
||
protected int checkTimeoutValue() { | ||
try { | ||
transaction = (Transaction) transactionManager.getTransaction(); | ||
return transaction.getTimeout(); | ||
} catch (Exception e) { | ||
throw new RuntimeException(e); | ||
} | ||
} | ||
} |
65 changes: 65 additions & 0 deletions
65
...java/org/jboss/as/test/integration/ejb/timerservice/tx/timeout/PrivateTxScheduleBean.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,65 @@ | ||
/* | ||
* JBoss, Home of Professional Open Source | ||
* Copyright 2010, Red Hat Inc., and individual contributors as indicated | ||
* by the @authors tag. See the copyright.txt in the distribution for a | ||
* full listing of individual contributors. | ||
* | ||
* This is free software; you can redistribute it and/or modify it | ||
* under the terms of the GNU Lesser General Public License as | ||
* published by the Free Software Foundation; either version 2.1 of | ||
* the License, or (at your option) any later version. | ||
* | ||
* This software is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
* Lesser General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public | ||
* License along with this software; if not, write to the Free | ||
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA | ||
* 02110-1301 USA, or see the FSF site: http://www.fsf.org. | ||
*/ | ||
package org.jboss.as.test.integration.ejb.timerservice.tx.timeout; | ||
|
||
import java.util.concurrent.CountDownLatch; | ||
import java.util.concurrent.TimeUnit; | ||
|
||
import javax.ejb.Schedule; | ||
import javax.ejb.Stateless; | ||
import javax.ejb.Timer; | ||
|
||
import org.jboss.ejb3.annotation.TransactionTimeout; | ||
|
||
/** | ||
* @author Tomasz Adamski | ||
*/ | ||
@Stateless | ||
public class PrivateTxScheduleBean extends AbstractTxBean { | ||
private static final CountDownLatch latch = new CountDownLatch(1); | ||
private static final int TIMER_CALL_WAITING_S = 30; | ||
|
||
private static volatile boolean timerServiceCalled = false; | ||
private static volatile int timeout = 0; | ||
|
||
@Schedule(second = "*", minute = "*", hour = "*", persistent = false, info = "info", timezone = "Europe/Prague") | ||
@TransactionTimeout(value = 5) | ||
private void timeout(Timer timer) { | ||
timeout = checkTimeoutValue(); | ||
timerServiceCalled = true; | ||
latch.countDown(); | ||
} | ||
|
||
public static boolean awaitTimerCall() { | ||
try { | ||
latch.await(TIMER_CALL_WAITING_S, TimeUnit.SECONDS); | ||
} catch (InterruptedException e) { | ||
throw new RuntimeException(e); | ||
} | ||
return timerServiceCalled; | ||
} | ||
|
||
public static int getTimeout() { | ||
return timeout; | ||
} | ||
|
||
} |
85 changes: 85 additions & 0 deletions
85
.../java/org/jboss/as/test/integration/ejb/timerservice/tx/timeout/PrivateTxTimeoutBean.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,85 @@ | ||
/* | ||
* JBoss, Home of Professional Open Source | ||
* Copyright 2010, Red Hat Inc., and individual contributors as indicated | ||
* by the @authors tag. See the copyright.txt in the distribution for a | ||
* full listing of individual contributors. | ||
* | ||
* This is free software; you can redistribute it and/or modify it | ||
* under the terms of the GNU Lesser General Public License as | ||
* published by the Free Software Foundation; either version 2.1 of | ||
* the License, or (at your option) any later version. | ||
* | ||
* This software is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
* Lesser General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public | ||
* License along with this software; if not, write to the Free | ||
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA | ||
* 02110-1301 USA, or see the FSF site: http://www.fsf.org. | ||
*/ | ||
package org.jboss.as.test.integration.ejb.timerservice.tx.timeout; | ||
|
||
import java.util.concurrent.CountDownLatch; | ||
import java.util.concurrent.TimeUnit; | ||
|
||
import javax.annotation.Resource; | ||
import javax.ejb.Remote; | ||
import javax.ejb.SessionContext; | ||
import javax.ejb.Stateless; | ||
import javax.ejb.Timeout; | ||
import javax.ejb.Timer; | ||
import javax.ejb.TimerConfig; | ||
import javax.ejb.TimerService; | ||
|
||
import org.jboss.ejb3.annotation.TransactionTimeout; | ||
|
||
/** | ||
* @author Tomasz Adamski | ||
*/ | ||
|
||
@Stateless | ||
@Remote(TimeoutBeanRemoteView.class) | ||
public class PrivateTxTimeoutBean extends AbstractTxBean implements TimeoutBeanRemoteView { | ||
|
||
private static final int TIMER_CALL_WAITING_S = 30; | ||
private static final int DURATION = 100; | ||
|
||
private static volatile CountDownLatch latch = new CountDownLatch(1); | ||
|
||
private static volatile boolean timerServiceCalled = false; | ||
private static volatile int timeout = 0; | ||
|
||
@Resource | ||
private SessionContext sessionContext; | ||
|
||
@Resource | ||
private TimerService timerService; | ||
|
||
@Override | ||
public void startTimer() { | ||
timerService.createSingleActionTimer(DURATION, new TimerConfig()); | ||
} | ||
|
||
@Timeout | ||
@TransactionTimeout(value = 5) | ||
private void timeout(final Timer timer) { | ||
timeout = checkTimeoutValue(); | ||
timerServiceCalled = true; | ||
latch.countDown(); | ||
} | ||
|
||
public static boolean awaitTimerCall() { | ||
try { | ||
latch.await(TIMER_CALL_WAITING_S, TimeUnit.SECONDS); | ||
} catch (InterruptedException e) { | ||
throw new RuntimeException(e); | ||
} | ||
return timerServiceCalled; | ||
} | ||
|
||
public static int getTimeout(){ | ||
return timeout; | ||
} | ||
} |
65 changes: 65 additions & 0 deletions
65
.../java/org/jboss/as/test/integration/ejb/timerservice/tx/timeout/PublicTxScheduleBean.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,65 @@ | ||
/* | ||
* JBoss, Home of Professional Open Source | ||
* Copyright 2010, Red Hat Inc., and individual contributors as indicated | ||
* by the @authors tag. See the copyright.txt in the distribution for a | ||
* full listing of individual contributors. | ||
* | ||
* This is free software; you can redistribute it and/or modify it | ||
* under the terms of the GNU Lesser General Public License as | ||
* published by the Free Software Foundation; either version 2.1 of | ||
* the License, or (at your option) any later version. | ||
* | ||
* This software is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
* Lesser General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public | ||
* License along with this software; if not, write to the Free | ||
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA | ||
* 02110-1301 USA, or see the FSF site: http://www.fsf.org. | ||
*/ | ||
package org.jboss.as.test.integration.ejb.timerservice.tx.timeout; | ||
|
||
import java.util.concurrent.CountDownLatch; | ||
import java.util.concurrent.TimeUnit; | ||
|
||
import javax.ejb.Schedule; | ||
import javax.ejb.Stateless; | ||
import javax.ejb.Timer; | ||
|
||
import org.jboss.ejb3.annotation.TransactionTimeout; | ||
|
||
/** | ||
* @author Tomasz Adamski | ||
*/ | ||
@Stateless | ||
public class PublicTxScheduleBean extends AbstractTxBean { | ||
private static final CountDownLatch latch = new CountDownLatch(1); | ||
private static final int TIMER_CALL_WAITING_S = 30; | ||
|
||
private static volatile boolean timerServiceCalled = false; | ||
private static volatile int timeout = 0; | ||
|
||
@Schedule(second = "*", minute = "*", hour = "*", persistent = false, info = "info", timezone = "Europe/Prague") | ||
@TransactionTimeout(value = 5) | ||
public void timeout(Timer timer) { | ||
timeout = checkTimeoutValue(); | ||
timerServiceCalled = true; | ||
latch.countDown(); | ||
} | ||
|
||
public static boolean awaitTimerCall() { | ||
try { | ||
latch.await(TIMER_CALL_WAITING_S, TimeUnit.SECONDS); | ||
} catch (InterruptedException e) { | ||
throw new RuntimeException(e); | ||
} | ||
return timerServiceCalled; | ||
} | ||
|
||
public static int getTimeout() { | ||
return timeout; | ||
} | ||
|
||
} |
87 changes: 87 additions & 0 deletions
87
...st/java/org/jboss/as/test/integration/ejb/timerservice/tx/timeout/PublicTxTimoutBean.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 @@ | ||
/* | ||
* JBoss, Home of Professional Open Source | ||
* Copyright 2010, Red Hat Inc., and individual contributors as indicated | ||
* by the @authors tag. See the copyright.txt in the distribution for a | ||
* full listing of individual contributors. | ||
* | ||
* This is free software; you can redistribute it and/or modify it | ||
* under the terms of the GNU Lesser General Public License as | ||
* published by the Free Software Foundation; either version 2.1 of | ||
* the License, or (at your option) any later version. | ||
* | ||
* This software is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
* Lesser General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public | ||
* License along with this software; if not, write to the Free | ||
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA | ||
* 02110-1301 USA, or see the FSF site: http://www.fsf.org. | ||
*/ | ||
package org.jboss.as.test.integration.ejb.timerservice.tx.timeout; | ||
|
||
import java.util.concurrent.CountDownLatch; | ||
import java.util.concurrent.TimeUnit; | ||
|
||
import javax.annotation.Resource; | ||
import javax.ejb.Remote; | ||
import javax.ejb.SessionContext; | ||
import javax.ejb.Stateless; | ||
import javax.ejb.Timeout; | ||
import javax.ejb.Timer; | ||
import javax.ejb.TimerConfig; | ||
import javax.ejb.TimerService; | ||
|
||
import org.jboss.ejb3.annotation.TransactionTimeout; | ||
|
||
/** | ||
* @author Tomasz Adamski | ||
*/ | ||
|
||
@Stateless | ||
@Remote(TimeoutBeanRemoteView.class) | ||
public class PublicTxTimoutBean extends AbstractTxBean implements TimeoutBeanRemoteView { | ||
|
||
private static final int TIMER_CALL_WAITING_S = 30; | ||
private static final int DURATION = 100; | ||
|
||
private static volatile CountDownLatch latch = new CountDownLatch(1); | ||
|
||
private static volatile boolean timerServiceCalled = false; | ||
private static volatile int timeout = 0; | ||
|
||
@Resource | ||
private SessionContext sessionContext; | ||
|
||
@Resource | ||
private TimerService timerService; | ||
|
||
@Override | ||
public void startTimer() { | ||
timerService.createSingleActionTimer(DURATION, new TimerConfig()); | ||
} | ||
|
||
@Timeout | ||
@TransactionTimeout(value = 5) | ||
public void timeout(final Timer timer) { | ||
timeout = checkTimeoutValue(); | ||
timerServiceCalled = true; | ||
latch.countDown(); | ||
} | ||
|
||
public static boolean awaitTimerCall() { | ||
try { | ||
latch.await(TIMER_CALL_WAITING_S, TimeUnit.SECONDS); | ||
} catch (InterruptedException e) { | ||
throw new RuntimeException(e); | ||
} | ||
return timerServiceCalled; | ||
} | ||
|
||
public static int getTimeout(){ | ||
return timeout; | ||
} | ||
|
||
|
||
} |
26 changes: 26 additions & 0 deletions
26
...java/org/jboss/as/test/integration/ejb/timerservice/tx/timeout/TimeoutBeanRemoteView.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,26 @@ | ||
/* | ||
* JBoss, Home of Professional Open Source | ||
* Copyright 2010, Red Hat Inc., and individual contributors as indicated | ||
* by the @authors tag. See the copyright.txt in the distribution for a | ||
* full listing of individual contributors. | ||
* | ||
* This is free software; you can redistribute it and/or modify it | ||
* under the terms of the GNU Lesser General Public License as | ||
* published by the Free Software Foundation; either version 2.1 of | ||
* the License, or (at your option) any later version. | ||
* | ||
* This software is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
* Lesser General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public | ||
* License along with this software; if not, write to the Free | ||
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA | ||
* 02110-1301 USA, or see the FSF site: http://www.fsf.org. | ||
*/ | ||
package org.jboss.as.test.integration.ejb.timerservice.tx.timeout; | ||
|
||
public interface TimeoutBeanRemoteView { | ||
void startTimer(); | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a chance that the same method might have processTxAttr() called on it twice, and if so, is there protection in that method to avoid any kind of duplication nonsense?
Patch otherwise looks reasonable to me.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Method processTxAttr() adds information about attributes and timeouts to maps. Keys in those maps are objects of class MethodTransactionAttributeKey. This class contains information about both method and context of invocation. So there is no protection against method being called many times, but running it many times will leave those maps in the same state. On the other hand, I see one more problem here. Before my fix transaction timeouts were added to public @timeout methods with context other than timer and it didn't prevented information about timeout to be propagated to those methods when they were executed from timer context.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this patch OK to merge as is, or do you want to try and verify/fix this second issue?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that this patch can be merged because the second issue is independent. I can leave the Jira open and investigate it further. If it required fix then I would prepare another patch.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK in that case this has my +1