EJB #Timeout not working - timer

I want to wake up ejb timer on every two second. For that I am creating ScheulerExpression as the code below...
package com.fks.nclp.ejb.timer.service;
import javax.annotation.PostConstruct;
import javax.annotation.Resource;
import javax.ejb.LocalBean;
import javax.ejb.ScheduleExpression;
import javax.ejb.Startup;
import javax.ejb.Timeout;
import javax.ejb.TimerConfig;
import javax.ejb.TimerService;
import com.sun.jersey.spi.resource.Singleton;
#LocalBean
#Singleton
#Startup
public class HelloWorldService {
#Resource
TimerService timerService;
#PostConstruct
public void initialize(){
System.out.println("EJB PRE CONSTRUCT");
ScheduleExpression expression = new ScheduleExpression();
//SET TIMER TO 2 SEC
expression.hour("*");
expression.minute("*");
expression.second("*/2");
timerService.createCalendarTimer(expression,new TimerConfig("TimerScheduler",false));
}
#Timeout
public void startTimer(){
System.out.println("THIS IS EJB TIMER PROGRAM");
}
}
But ... the EJB container is not waking up the scheduler after every two second.
Any Suggestion on this ?
How can I make the expression to wake up every two second.
Thanks,
Gunjan.

There are two things which might be causing problem :
The import statement seems incorrect, which is com.sun.jersey.spi.resource.Singleton, but should be javax.ejb.Singleton.
Try removing #LocalBean annotation.

Related

Apache Flink - Nothing printed to the output, even if the exit code is 0

I am using Apache Flink 1.16.0 version.
I am trying to do a simple CEP by printing the elements to the console
For any reason, there is nothing printed to the console, even the process finished with exit code 0.
Here is the code:
import org.apache.flink.cep.*;
import org.apache.flink.cep.functions.PatternProcessFunction;
import org.apache.flink.cep.pattern.Pattern;
import org.apache.flink.streaming.api.datastream.DataStream;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;
import org.apache.flink.util.Collector;
import java.util.List;
import java.util.Map;
public class Main {
public static void main(String[] args) throws Exception {
final StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
DataStream<String> input = env.fromElements("adrian", "cincu", "diana", "sichitiu");
Pattern<String, ?> pattern = Pattern.begin("start");
PatternStream<String> patternStream = CEP.pattern(input, pattern);
DataStream<String> matches = patternStream.process(new PatternProcessFunction<String, String>() {
#Override
public void processMatch(Map<String, List<String>> map,
Context context,
Collector<String> collector) throws Exception {
collector.collect(map.get("start").toString());
}
});
matches.print();
env.execute("myjob");
}
}
Any clue?
I think the issue in this case is that Your pattern doesn't make sense. It will just start matching events, but there is no actual requirement for events to match the pattern, so every event (String in Your case) will match the same Pattern, this will cause the Pattern to stay open forever and never emit any actual data.
You may want to add some kind of requirements to make sure that pattern actually gets closed.
There is some info about how to define Patterns in the [docs].1

Compilation error in Selenium Webdriver : field package.Classfile.driver is not visible

I am getting some sort of compilation error it seems.
I have ‘Common.java’ class inside ‘base’ package. It's a program for starting firefox driver. That, I have kept it in the separate package to make it a one time effort and modularity purpose.
I am calling this class file inside the child class ‘tc_01.java’. This TC_01.jave program is in another package ‘testing’. This TC_01.java file is actually accessing driver from Common.java and start the browser and try some login and logout actions.
My child class TC_01.java is showing me compilation error and Error Message on Mouse Hover is – > “field Common.driver is not visible”.
And, at Console : "java.lang.Error: Unresolved compilation problems:
The field Common.driver is not visible"
My Analysis: It seems TC_01.java file is not able to access the 'driver' from 'Common.java'.
But, I have already written 'extends' keyword for it to inherit the properties.
Please guide me. Thanks
Here is my code:->
package base;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
public class Common {
public FirefoxDriver driver;
#BeforeMethod
public void BM(){
System.setProperty(“webdriver.gecko.driver”,”D://Rajiv//Selenium//geckodriver.exe”);
driver = new FirefoxDriver();
driver.get(“http://automationpractice.com/index.php”);
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
}
#AfterMethod
public void CM(){
driver.close();
}
}
# Pakage – testing; Class – Tc_01.java
package testing;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
import org.testng.Assert;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
import base.Common;
public class TC_01 extends Common{
public FirefoxDriver driver;`
#Test
public void TM(){
System.out.println(“Selenium Webdriver Script in Firefox browser using Gecko` `Driver | AutomationPractice.com PAGE LAUNCHED”);
WebDriverWait wait = new WebDriverWait(driver, 30);
wait.until(ExpectedConditions.visibilityOfElementLocated(By.id(“search_query_top”)));
try{
String expectedTitle = “My Store”;
System.out.println(“ExpectedTile = “+expectedTitle );
String actualTitle = driver.getTitle();
System.out.println(“The actual Title of the Page is = “+actualTitle);
Assert.assertEquals(actualTitle, expectedTitle);*/
System.out.println(“Control has reached here”);
driver.findElementByClassName(“login”).click(); // field common.driver is not visible
driver.findElementById(“email”).sendKeys(“*****#yahoo.com”);
driver.findElementById(“passwd”).sendKeys(“*****”);
driver.findElementById(“SubmitLogin”).click();
driver.findElementByClassName(“logout”).click();
System.out.println(“Sucessfully Logout from the Application”);
}catch (Exception e){
e.printStackTrace();
}
}
}
I was able to find the root cause for this issue.
It wasted my 3 days before i asked for help here in this forum.
As i had analysed initially, i had mentioned my driver properties in parent class and was accessing it in Child Class. There was some name mismatch. When it was trying to inherit the properties from parent, it was not accessible and giving me compilation error. I renamed the parent class name to the same name that i was giving while extending in Child Class. And, it worked.
Thanks again to all of you. It is such a wonderful forum to discuss your issue between each other and getting its resolution.

AsyncFunction - Bug collecting throwable in unorder mode

I am experiencing an infinite loop using an AsyncFunc in unordered mode.
It can be reproduced using the following code
import org.apache.flink.streaming.api.datastream.AsyncDataStream;
import org.apache.flink.streaming.api.datastream.DataStream;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;
import org.apache.flink.streaming.api.functions.async.AsyncFunction;
import org.junit.Test;
import java.util.Arrays;
import java.util.Collections;
import java.util.concurrent.TimeUnit;
public class AsyncTest {
#Test
public void test() throws Exception {
StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
DataStream<Integer> withTimestamps = env.fromCollection(Arrays.asList(1,2,3,4,5));
AsyncDataStream.unorderedWait(withTimestamps,
(AsyncFunction<Integer, String>) (input, collector) -> {
if (input == 3){
collector.collect(new RuntimeException("Test"));
return;
}
collector.collect(Collections.singleton("Ok"));
}, 10, TimeUnit.MILLISECONDS)
.returns(String.class)
.print();
env.execute("unit-test");
}
}
My guess would be that the UnorderedStreamElementQueue is the reason of the infinite loop.
It seems to add the StreamElementQueueEntry containing the failing future into its firstSet field but never removes it (as this failing future is not triggering the onCompleteHandler method).
Anyone knows if this could be right or if I am making a mistake in my code?
There is indeed a bug in the AsyncWaitOperator. The problem is that it does not react to results which are exceptions (user exceptions as well as timeout exceptions).
In the case of ordered waiting, this causes that exceptional results are only detected if another async result has been completed (without an exception).
In the case of unordered waiting, this causes that the StreamElementQueueEntry is never moved from the firstSet into the completedQueue.
There is an issue for this problem. It will hopefully be fixed in the next couple of days.

One of the #Test code block doesn't execute

The TocheckApproval() code block doesnot get executed
Can someone please suggest why this is happening and what steps do i need to take to execute both the #Test blocks
I'm not sure whether method order is guaranteed by TestNG framework.
If you want the method order like run the test only after some tests ran (and marked as PASS), you can use dependsOnMethods or dependsOnGroups
Eg:
import org.junit.FixMethodOrder;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
import org.testng.asserts.Assertion;
public class TestExample {
#BeforeTest
public void beforetest(){
System.out.println("before test ");
}
#Test
public void Tocheckapproval() {
System.out.println("in the method: Tocheckapproval");
}
#Test(dependsOnMethods = {"Tocheckapproval"})
public void TocheckRequestDecline() {
System.out.println("in the method: TocheckRequestDecline");
}
#AfterTest
public void aftertest() {
System.out.println("after test");
}
}
If you want to define the method order of your choice and the tests should not depend on other tests, then instead of dependecyOn* (methods, groups), you can use method Interceptors.
method Interceptors provides the list of test methods that are going to run as one of the argument, then you can re-arrange as per your needs.
References:
http://testng.org/doc/documentation-main.html#methodinterceptors
http://beust.com/weblog/2008/03/29/test-method-priorities-in-testng/
You haven't set any test priorities, that's why!
This is very easy to do, just stick the priority next to your #Test tag.
#Test (priority=1)
public void ToTestApproval(){
//do some stuff
}
#Test (priority=2)
public void ToCheckRequestDecline(){
//do some more stuff
}
As Naveen, mentioned above you can further refine the desired behaviour by using dependsOnMethods and dependsOnGroups.
PS. If this does not work, then it could be down to the #Test tag itself. Please double check that you are using TestNG annotation instead of Junit!
Best of luck!

EJB Timer JEE6 does not starts automatically

Why this time does not work? What am I missing?
I'm using GlassFish 3.1.2.
package foo.bar;
import javax.ejb.Schedule;
import javax.ejb.Singleton;
#Singleton
public class MySimpleTimerEJB {
#Schedule(second="*/1")
public void foo() {
System.out.println("Foo");
}
}
Solved,
as Piotr suggested, i have to inform minute and hour aswell, since they have a default zero value.
also i used the persistent=false attribute, and got the expected result.
#Schedule(second="*", minute="*",hour="*", persistent=false)
public void foo() {
System.out.println("Foo");
}
If you want that the scheduling counter starts immediately after the deployement you have to add the #startup annotation so the container will handle and start scheduling management

Resources