Is it possible to start both client and server nodes in the same JVM?
Yes, you can start several nodes within one JVM. You only need to make sure that IgniteConfiguration.getGridName() property is unique for each node. Here is the example:
public static void main(String[] args) {
Ignite server = startNode("server-node");
Ignite client = startNode("client-node");
...
}
private static Ignite startNode(String name) {
IgniteConfiguration cfg = new IgniteConfiguration();
cfg.setGridName(name);
return Ignition.start(cfg);
}
Related
I'd like to know if it is possible to use karate with AWS device farm for Android and iOS testing. If this is possible, are there any example of configuration somewhere ?
The only thing related to karate and AWS device farm I can find is this repository but it's about web application testing.
Thanks
Yes, AWS Device Farm does support executing the Karate framework for web testing across Android and iOS devices. The major difference between desktop and mobile testing on AWS Device Farm is that, for mobile testing, we require that tests be packaged and uploaded to our service for server-side execution. For example, in the following code, we use a simple conditional branch to check "are we running server-side for mobile devices or client-side for desktop browser devices":
class DeviceFarmWebTests(unittest.TestCase):
def setUp(self):
if os.getenv("DEVICEFARM_DEVICE_NAME"):
print("Running my test on a real physical device in Device Farm (server-side)")
url = "http://127.0.0.1:4723/wd/hub"
desired_capabilities = {}
else:
print("Running my test on a desktop browser in Device Farm (client-side)")
session = boto3.Session(profile_name='simsjon')
devicefarm = session.client('devicefarm', region_name='us-west-2')
project_arn = create_project(devicefarm, "Test Desktop Browsers Project")
print("Project ARN:", project_arn)
url = create_presigned_url(devicefarm, arn=project_arn)
print("Creating a new remote web driver session at:", url)
desired_capabilities = DesiredCapabilities.CHROME
self.driver = webdriver.Remote(command_executor=url,
desired_capabilities=desired_capabilities)
print("A new WebDriver session has been created. SessionId:", self.driver.session_id)
def test_main(self):
...
Please see our instructions here for packaging and uploading tests like this, which will communicate with AWS Device Farm mobile devices through an Appium server (and thus are referred to as Appium tests): https://docs.aws.amazon.com/devicefarm/latest/developerguide/test-types-appium.html
For Running directly in aws device farm:
Modify your existing karate project according to the below documentation:
https://docs.aws.amazon.com/devicefarm/latest/developerguide/test-types-appium.html
steps are pretty straightforward, updating pom.xml, creating assembly/zip.xml, and run mvn package to create jar files which you have to zip and upload to devicefarm project.
I noted that running on device farm by directly uploading your project only works with Junit4 hence you can only use karate-junit4 in your dependency
For Local:
Refer DeviceFarmTarget class in https://github.com/ptrthomas/karate-devicefarm-demo and implement a similar one in you existing karate project
public class AwsDeviceFarmMobileTarget implements Target {
private String arn;
private String driverType = "android";
public AwsDeviceFarmMobileTarget(Map<String, Object> options) {
arn = (String) options.get("arn");
if (arn == null) {
throw new RuntimeException("arn is null");
}
// update driver type and browserName if needed
}
#Override
public Map<String, Object> start(ScenarioRuntime sr) {
sr.logger.info("starting driver using: {}", AwsDeviceFarmMobileTarget.class);
DeviceFarmClient client = DeviceFarmClient.builder().region(Region.US_WEST_2).build();
CreateTestGridUrlRequest request = CreateTestGridUrlRequest.builder()
.expiresInSeconds(300)
.projectArn(arn)
.build();
CreateTestGridUrlResponse response = client.createTestGridUrl(request);
String webDriverUrl = response.url();
sr.logger.info("aws url provisioned: {}", webDriverUrl);
Map<String, Object> map = new HashMap();
map.put("type", driverType);
map.put("start", false);
map.put("webDriverUrl", webDriverUrl);
// this is needed because it can take a minute or two for the "desktop" to be provisioned by aws
map.put("httpConfig", Collections.singletonMap("readTimeout", 120000));
// refer: https://docs.aws.amazon.com/devicefarm/latest/testgrid/techref-support.html
Map<String, Object> session = new HashMap();
map.put("webDriverSession", session);
Map<String, Object> capabilities = new HashMap();
session.put("capabilities", capabilities);
// for some reason, both are needed for aws device farm
session.put("desiredCapabilities", capabilities);
return map;
}
#Override
public Map<String, Object> stop(ScenarioRuntime sr) {
return Collections.EMPTY_MAP;
}
}
I am trying to call my simulation model from another java program. I followed the official instructions to have the codes like below:
package test;
public class UserMain {
public UserMain(){};
public void start(){
String[] args = new String[]{"D:\\user\\model\\Repast_java\\IntraCity_Simulator\\IntraCity_Simulator.rs"};
// repast.simphony.runtime.RepastMain.main(args);
}
public static void main(String[] args) {
UserMain um = new UserMain();
um.start();
}
}
It didn't work. I think it's due to the wrong classpath. How to configure it correctly?
Note that you need to have repast.simphony.runtime/bin and the jars in repast.simphony.runtime/lib on your classpath since the runtime needs these to start.
This is more of a Java or Eclipse question about how to use Java's class path. But briefly, if you are running from the command line, you can use the -cp argument to specify the classpath. A quick google should provide the details. In Eclipse, the classpath is specified in dependencies tab in the Run Configuration (Run -> Run Configurations) for your application.
I have AWS instance with two servers. The first one is win.server with selenium hub and the second one is ubuntu machine as selenium node. Sometimes selenium node breaks and i'm looking for the best way to check availability of this node and reboot the machine if it was broken. Thanks in advance.
You can check if the node is broken or disconnected using below code by checking node's session :
import javax.ws.rs.core.MediaType;
import com.sun.jersey.api.client.Client;
import com.sun.jersey.api.client.ClientResponse;
import com.sun.jersey.api.client.WebResource;
public class TestJerseyClient {
public static void main(String[] args) {
String nodeURL = "http://10.11.208.114:5555/wd/hub/sessions"; // replace your IP and port here
System.out.println(isNodeDisconnected(nodeURL));
}
/** It will check if any node is disconnected from hub in Selenium Grid
* #param nodeURL
* #return node connection status
*/
private static boolean isNodeDisconnected(String nodeURL) {
boolean isNodeDisconnected= false;
try {
Client client = Client.create();
WebResource webResource = client.resource(nodeURL);
ClientResponse response = webResource.accept(MediaType.APPLICATION_JSON).get(ClientResponse.class);
String output = response.getEntity(String.class);
System.out.println(output);
} catch (Exception e) {
if (e.getMessage().contains("java.net.ConnectException")) {
isNodeDisconnected= true;
}
System.out.println("The node is disconneted and needs to be connected again !!!!!!!!!");
}
return isNodeDisconnected;
}
}
if it gives "true" then you can use AWS API to reboot the server or can reboot it manually.
use this dependency in your pom.xml :
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-bundle</artifactId>
<version>1.7</version>
</dependency>
Hope it helps you:)
When starting an Apache Ignite client (Ignite version 2.3.0, connecting to the (single) cluster node seems to work at first. But then I get the following exception
Jan 04, 2018 5:18:23 PM org.apache.ignite.logger.java.JavaLogger error
SEVERE: Failed to process custom exchange task: ClientCacheChangeDummyDiscoveryMessage [reqId=c1d6d9fd-a2be-4826-9459-05912ad1f5a5, cachesToClose=null, startCaches=[risfahrt_v5_matched_intern_partitioned_by_fahrtid]]
java.lang.NullPointerException
at org.apache.ignite.internal.processors.cache.CacheGroupContext.<init>(CacheGroupContext.java:191)
at org.apache.ignite.internal.processors.cache.GridCacheProcessor.startCacheGroup(GridCacheProcessor.java:1850)
at org.apache.ignite.internal.processors.cache.GridCacheProcessor.prepareCacheStart(GridCacheProcessor.java:1792)
at org.apache.ignite.internal.processors.cache.CacheAffinitySharedManager.processClientCacheStartRequests(CacheAffinitySharedManager.java:428)
at org.apache.ignite.internal.processors.cache.CacheAffinitySharedManager.processClientCachesChanges(CacheAffinitySharedManager.java:611)
at org.apache.ignite.internal.processors.cache.GridCacheProcessor.processCustomExchangeTask(GridCacheProcessor.java:338)
at org.apache.ignite.internal.processors.cache.GridCachePartitionExchangeManager$ExchangeWorker.processCustomTask(GridCachePartitionExchangeManager.java:2142)
at org.apache.ignite.internal.processors.cache.GridCachePartitionExchangeManager$ExchangeWorker.body(GridCachePartitionExchangeManager.java:2231)
at org.apache.ignite.internal.util.worker.GridWorker.run(GridWorker.java:110)
at java.lang.Thread.run(Thread.java:745)
Ignite client is started as follows:
IgniteConfiguration igniteConfiguration = new IgniteConfiguration();
igniteConfiguration.setClientMode(clientMode);
TcpDiscoverySpi tcpDiscoverySpi = new TcpDiscoverySpi();
TcpDiscoveryVmIpFinder ipFinder = new TcpDiscoveryVmIpFinder();
ipFinder.setAddresses(servers);
tcpDiscoverySpi.setIpFinder(ipFinder);
igniteConfiguration.setDiscoverySpi(tcpDiscoverySpi);
Ignite ignite = Ignition.start(igniteConfiguration);
The cache is configured as follows:
CacheConfiguration<String, V> cacheConfiguration = new CacheConfiguration<>();
cacheConfiguration.setName(cacheName);
cacheConfiguration.setCacheMode(CacheMode.PARTITIONED);
NearCacheConfiguration<String, V> nearCacheConfiguration = new NearCacheConfiguration<>();
nearCacheConfiguration.setNearEvictionPolicy(new LruEvictionPolicy<>(nearCacheSize));
IgniteCache<String, V> cache = ignite.getOrCreateCache(cacheConfiguration, nearCacheConfiguration);
The solution was to avoid underscores ("_") in the cache name. After doing so, everything worked without problems.
I have to create a java application that will start a node and connect it to the hub. So far I have been able to do so when the hub and node are on the same computer, but as soon as I try to connect on another machine hub, the registering process hang forever.
I tried different approach. To just call my bat file function in code.
String command = "java -jar selenium-server-standalone-2.26.0.jar -role node -hub http://192.168.0.11:4444/grid/register -port 4449 -Dwebdriver.chrome.driver=data\\driver\\chromedriver.exe -Dwebdriver.ie.driver=data\\driver\\IEDriverServer.exe -nodeConfig data\\configurations.json";
try
{
pr = Runtime.getRuntime().exec(command);
}
catch(Exception e)
{
e.printStackTrace();
}
The command work when called from a bat file, but in code it only works if the node and hub are on the same computer.
I also tried to use the RegistrationRequest.
RegistrationRequest req = new RegistrationRequest();
req.setRole(GridRole.NODE);
Map<String, Object> nodeConfiguration = new HashMap<String,
Object>();
nodeConfiguration.put(RegistrationRequest.AUTO_REGISTER, true);
nodeConfiguration.put(RegistrationRequest.HUB_HOST, "192.168.100.66");
nodeConfiguration.put(RegistrationRequest.HUB_PORT, 4444);
nodeConfiguration.put(RegistrationRequest.PORT, 5555);
URL remoteURL = new URL("http://" + "192.168.100.66" + ":" + 5555);
nodeConfiguration.put(RegistrationRequest.PROXY_CLASS, "org.openqa.grid.selenium.proxy.DefaultRemoteProxy");
nodeConfiguration.put(RegistrationRequest.MAX_SESSION, 1);
nodeConfiguration.put(RegistrationRequest.CLEAN_UP_CYCLE, 2000);
nodeConfiguration.put(RegistrationRequest.REMOTE_HOST, remoteURL);
nodeConfiguration.put(RegistrationRequest.MAX_INSTANCES, 1);
req.setConfiguration(nodeConfiguration);
remote = new SelfRegisteringRemote(req);
remote.startRemoteServer();
remote.startRegistrationProcess();
Same result, when I try to run on another computer hub, it hand at the registering process.
INFO - Registering the node to hub :http://192.168.100.66:4444/grid/register
any idea why? or how to do it.
I figured out my problem, which is really simple to fix. In my code I had
URL remoteURL = new URL("http://" + "192.168.100.66" + ":" + 5555);
I just needed to replace the ip address by my local ip address, not the hub ip address, and it worked. Which is weird cause I am pretty sure I took this code from somewhere online and he had a variable for the ip, and it was the same for remoteURL and the HUB_HOST
well. Not sure whether is suitable for you but I'd like to share approach I use on my project.
I've got remote machine with 192.168.4.52 IP and selenium stanadlone server running on it.
All selenium test suites I got locally.
So to run my selenium test suite on remote machine I simply use these settings in BaseSeleniumTest.java on my local machine:
....
#BeforeClass
public static void firefoxSetUp() throws MalformedURLException {
DesiredCapabilities capability = DesiredCapabilities.firefox();
driver = new RemoteWebDriver(new URL("http://192.168.4.52:4444/wd/hub"), capability);
driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
driver.manage().timeouts().pageLoadTimeout(30, TimeUnit.SECONDS);
driver.manage().window().setSize(new Dimension(1920, 1080));
}
#Before
public void homePageRefresh() throws IOException {
driver.manage().deleteAllCookies();
driver.get(propertyKeysLoader("login.base.url"));
}
#AfterClass
public static void closeFirefox(){
driver.quit();
}
where string
driver = new RemoteWebDriver(new URL("http://192.168.4.52:4444/wd/hub"), capability);
indicates IP of machine which I want to run my selenium test siute on.
I'm starting server on remote machine with this command:
java -jar selenium-server-standalone-2.26.0.jar in cmd before I run my test suite.
Hope it be helpful for you.