I'm trying to run headless tests from Jenkins. This works fine for HTML tests when I specify the HTML test suite. But now I want to run selenium-2 tests against the same selenium server.
I tried this:
Execute shell:
export DISPLAY=":99" && java -jar /var/lib/selenium/selenium-server.jar
But this seems to be hang until I stopped the server manually. How do I start the selenium server in such a way that my selenium RC tests invoked through grails ?
There is no special method to "start" selenium server to be used by any particular language. When you start selenium server it will start listening on a port for incoming requests. You should be having a line of code inside your tests to point your tests to the selenium server. I don't know grails. In java it would be
Selenium sel = new DefaultSelenium("host","port","browsername","baseurl")
> host - IP of the machine where server is started
> port - port number on which selenium server is listening. This is
usually 4444 if you don't specify anything
> browsername-Browser on which you want the tests to be
> run baseURL- base URL of the web app you need to test.
The equivalent method for this in grails should get you working.
EDIT - JAVA code to start selenium server:
Selenium sel;
int port=9999;
public static SeleniumServer server;
public void startSeleniumServer() throws Exception {
try {
ServerSocket serverSocket = new ServerSocket(port);
serverSocket.close();
//Server not up, start it
try {
RemoteControlConfiguration rcc = new RemoteControlConfiguration();
rcc.setPort(port);
server = new SeleniumServer(false, rcc);
} catch (Exception e) {
System.err.println("Could not create Selenium Server because of: "
+ e.getMessage());
e.printStackTrace();
}
try {
server.start();
System.out.println("Server started");
} catch (Exception e) {
System.err.println("Could not start Selenium Server because of: "
+ e.getMessage());
e.printStackTrace();
}
} catch (BindException e) {
System.out.println("Selenium server already up, will reuse...");
}
}
public void stopSeleniumServer(){
if (server != null)
{
try
{
server.stop();
}
catch (Exception e)
{
e.printStackTrace();
}
}
System.out.println("Selenium server stopped..");
}
public void startSeleniumRC() throws Exception{
sel=new DefaultSelenium("localhost",
port,
"*firefox",
"http://www.google.com");
sel.start();
}
public void stopSeleniumRC()
{
sel.shutDownSeleniumServer();
}
Related
I'm able to create docker container for ACE-TAO service , and able to access it from parent windows machine using port-forwarding concept.
From browser i try to hit the localhost:forward-port and getting "ERR_EMPTY_RESPONSE" and TAO service is running in docker container.
If I want to verify in local, whether its connected properly or not.
How can I write Java code to verify?
The following java code connects to localhost:17500 and prints out a message saying whether or not it could create a tcp connection.
import java.io.*;
import java.net.*;
class TCPClient
{
public static void main(String argv[]) throws Exception
{
try {
Socket clientSocket = new Socket("localhost", 17500);
System.out.println("Could connect");
}
catch (ConnectException e) {
System.out.println("Cannot connect");
}
}
}
I tried enabling the JMX for grizzly server. I added the gmbal-api-only-3.1.0 jar file to the project and wrote the following simple code :
public class Main {
public static void main(String[] args) {
HttpServer gws = new HttpServer();
NetworkListener listener1 = new NetworkListener("listener1", "localhost", 19080);
gws.addListener(listener1);
try {
gws.start();
gws.getServerConfiguration().setJmxEnabled(true);
System.in.read();
} catch (IOException ioe) {
ioe.printStackTrace();
System.exit(1);
} finally {
try {
gws.stop();
} catch (Exception ignored) {}
}
}
}
I ran this program and opened it up in the JConsole, but the JConsole do not show any MBean for the grizzly server in spite of using setJMXEnabled(true).
Please tell me what could be missing here or what is wrong with the code? Else, please suggest how to enable JMX for grizzly and how to verify it. I tried using the "Grizzly HTTP JMX Server Monitoring" approach given on the link : https://grizzly.java.net/monitoring.html
I've been plying with RMI recently and while I managed to make it work on locahost I've been having all sorts of problem when trying to use a remote server. Here's the basic code I'm trying to run:
Server:
public class RmiServer extends UnicastRemoteObject implements RmiServerIntf {
public static final String MESSAGE = "Hello world";
public RmiServer() throws RemoteException {
}
public String getMessage() {
return MESSAGE;
}
public static void main(String args[]) {
System.out.println("RMI server started");
if (System.getSecurityManager() == null) {
System.setSecurityManager(new RMISecurityManager());
System.out.println("Security manager installed.");
} else {
System.out.println("Security manager already exists.");
}
try {
LocateRegistry.createRegistry(1099);
System.out.println("java RMI registry created.");
} catch (RemoteException e) {
e.printStackTrace();
}
try {
RmiServer obj = new RmiServer();
Naming.rebind("rmi://localhost/RmiServer", obj);
System.out.println("PeerServer bound in registry");
} catch (Exception e) {
e.printStackTrace();
}
}
}
Remote class interface:
public interface RmiServerIntf extends Remote {
public String getMessage() throws RemoteException;
}
Client:
public class RmiClient {
RmiServerIntf obj = null;
public String getMessage() {
try {
obj = (RmiServerIntf)Naming.lookup("rmi://54.229.66.xxx/RmiServer");
return obj.getMessage();
} catch (Exception e) {
e.printStackTrace();
return e.getMessage();
}
}
public static void main(String args[]) {
if (System.getSecurityManager() == null) {
System.setSecurityManager(new RMISecurityManager());
}
RmiClient cli = new RmiClient();
System.out.println(cli.getMessage());
}
}
rmi.policy file:
grant {
permission java.security.AllPermission;
};
I compiled the classes and created a stub for the server. Then I placed client, stub, interface and policy on my machine and server, stub, interface and policy on the remote machine. The remote server being a Linux machine I made all the files executable. I also added a rule on the local firewall allowing port 1099, and opened all ports on the remote machine
After this I navigated to the server's directory on the remote machine and inserted the following command:
java -Djava.security.policy=rmi.policy RmiServer
This didn't give me problems so I went back to the local machine and entered
java -Djava.security.policy=rmi.policy RmiClient
I wait, and wait and I get the error message:
Connection refused to host: 172.31.xx.xx; nested exception is: java.net.ConnectException: Connection timed out: connect
I've been fighting with these connection errors all day yesterday and this is as far as I got. I'm sure there's only one very small thing I'm still doing wrong but I just can't find what it is.
This may not solve your problem, but I've had similar issues with JPPF (via Java RMI) on Linux. The solution was to ensure that the ephemeral port range on the Client-side machine covered only ports that were allowable by the Client-side's local firewall. E.g., if your firewall allows ports 48000 to 64000 to be connected to by an external machine, ensure that your ephemeral port range also falls within 48000 to 64000. Give that a try and let us know what happens.
System.setProperty("java.rmi.server.hostname","10.0.3.73");
Please use the above statements in your RMIServer side code, and try and connect from remote client again. It worked for me
how to run java tcp server in window azure?
can window azure do it?
I find so many article about java application for window azure,they is that open a JSP web project in eclipse, and than use worker role publish it in window azure, but my tcp server is general java project, so how to publish it to window azure?
my tcp server:
public class test {
private static int serverport = 12345;
private static ServerSocket serverSocket;
public static void main(String[] args) {
try {
serverSocket = new ServerSocket(serverport);
System.out.println("Server is start.");
while (!serverSocket.isClosed()) {
System.out.println("Wait new clinet connect!");
waitNewPlayer();
}
} catch (IOException e) {
System.out.println("Server Socket ERROR");
}
}
public static void waitNewPlayer() {
try {
Socket socket = serverSocket.accept();
System.out.println(socket.getInetAddress().getHostAddress()+"'s socket is connected now!");
createNewUser(socket);
} catch (IOException e) {
}
}
public static void createNewUser(final Socket socket) {
Thread t = new Thread(new Runnable() {
#Override
public void run() {
try {
PrintWriter out = new PrintWriter( new BufferedWriter( new OutputStreamWriter(socket.getOutputStream())),true);
out.println("nangnang");
} catch (IOException e) {
System.out.println("Socket is closed!");
}
System.out.println("This socket is removed form the player array!");
}
});
t.start();
}
}
You should be able to run an app like this in Azure, but you'll need to take care of a couple of things:
Open an Input Endpoint for your worker role - this opens the port to the outside world. You then need to either map it to the exact same port internally, or let Azure pick a port for you (and then you can ask the role environment which port you've been assigned, and open that port in your code instead of 12345)
For all your println's, you'd need to remote-desktop to see them, or you need to push them to diagnostics logging so you can see those debug statements via an external tool like Cerebrata's Diagnostics Manager.
As far as publishing: It's the same as the jsp examples you've seen: you build an Azure project to go along with your Java project, you set up the role size and instance count, create input endpoints, optionally create a cache, set up configuration settings for storage accounts, create a package to run in emulator or in the cloud, etc.
You might also want to try AzureRunMe which also supports Azure Java Project. http://azurerunme.codeplex.com/
I want to stop a server running on port 8080. In my java application, whenever application is closed, also this server needs to be stopped. But I could not find any solution except stopping the server manually. Is there any way to stop a server with codes ? By the way, I am using Windows 7
How are you starting SymmetricDs? As a windows service, as a WAR or embedded in you application?
Looking at the user guide it seems that if you could embed it in your code you ought to be able to start and stop it directly. More details in the user guide along with the following example code.
import org.jumpmind.symmetric.SymmetricWebServer;
public class StartSymmetricEngine {
/**
* Start an engine that is configured by two properties files. One is
* packaged with the application and contains overridden properties that are
* specific to the application. The other is found in the application's
* working directory. It can be used to setup environment specific
* properties.
*/
public static void main(String[] args) throws Exception {
SymmetricWebServer node = new SymmetricWebServer(
"classpath://my-application.properties");
// this will create the database, sync triggers, start jobs running
node.start(8080);
// this will stop the node
node.stop();
}
}
try {
// Execute a command to terminate your server
String command = "command to stop your server";
Process child = Runtime.getRuntime().exec(command);
} catch (IOException e) {
}
Why don't you check Cargo? It provides a Java API to start/stop Java containers. You can find the list of supported containers in the home page.
Since i did not see the code , how are creating server and accepting connection ,below
i have given you the following ooptions.you should try to implement the firstway ,
rest of the option wont guarantee whether correct process will be killed.
public void stopServer()
{
threadReference.interrupt();
}
while(!Thread.interrupted())
{
// Accept Server Connection
try
{
Thread.sleep(1000);
}
catch(InterruptedException ex)
{
Thread.currentThread().interrupt();
}
}
Runtime.getRunTime().addShutDownHook(new Thread()
{
public void run()
{
try
{
ref.stop();
} catch (IOException e)
{
// close server socket
// other clean up
e.printStackTrace();
}
}
});
you need to specify this in Runtime.getRuntime() TASKKILL /F /IM or there is a jps which is better to kill relevant process.
try
{
Process p = Runtime.getRuntime().exec("TASKKILL /F /IM communicator*");
BufferedReader in =
new BufferedReader(new InputStreamReader(p.getInputStream()));
String result = null;
while ((result= in.readLine()) != null) {
if ( "SUCCESS".equals(result.substring(0,7))
{
break;
}
}
} catch (IOException e)
{
e.printStackTrace();
}