-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
69d539b
commit c59e5a6
Showing
30 changed files
with
1,882 additions
and
56 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
.project | ||
target | ||
bin | ||
.classpath | ||
/test-output | ||
/.settings | ||
**/.settings | ||
/com | ||
/application.log | ||
/sql.log | ||
*.checkstyle | ||
.idea | ||
*.iml | ||
test-output | ||
*.log | ||
/reports | ||
/out | ||
dependency-reduced-pom.xml | ||
.DS_Store |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xmlns="http://maven.apache.org/POM/4.0.0" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<groupId>com.zebrunner</groupId> | ||
<artifactId>mcloud-node-agent</artifactId> | ||
<version>1.0</version> | ||
<packaging>jar</packaging> | ||
<name>Zebrunner Device Farm (Selenium Grid Node Agent)</name> | ||
<properties> | ||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | ||
<maven-shade-plugin.version>3.5.0</maven-shade-plugin.version> | ||
<maven-compiler-plugin.version>3.11.0</maven-compiler-plugin.version> | ||
</properties> | ||
<dependencies> | ||
<dependency> | ||
<!--we need it to reuse benefits of zebrunner testng agent for webdriver | ||
sesssion(s) declaration --> | ||
<groupId>net.bytebuddy</groupId> | ||
<artifactId>byte-buddy</artifactId> | ||
<version>1.14.5</version> | ||
</dependency> | ||
</dependencies> | ||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-shade-plugin</artifactId> | ||
<version>${maven-shade-plugin.version}</version> | ||
<executions> | ||
<execution> | ||
<phase>package</phase> | ||
<goals> | ||
<goal>shade</goal> | ||
</goals> | ||
<configuration> | ||
<minimizeJar>false</minimizeJar> | ||
<transformers> | ||
<!-- Don't do this: Avoid adding anything that makes shade create or modify a manifest file. | ||
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer"> | ||
<mainClass>com.mypackage.MyMainClass</mainClass> | ||
</transformer> | ||
--> | ||
<!-- Add a transformer to exclude any other manifest files (possibly from dependencies). --> | ||
<transformer implementation="org.apache.maven.plugins.shade.resource.DontIncludeResourceTransformer"> | ||
<resource>MANIFEST.MF</resource> | ||
</transformer> | ||
|
||
<!-- Add a transformer to include your custom manifest file. --> | ||
<transformer implementation="org.apache.maven.plugins.shade.resource.IncludeResourceTransformer"> | ||
<resource>META-INF/MANIFEST.MF</resource> | ||
<file>src/main/resources/META-INF/MANIFEST.MF</file> | ||
</transformer> | ||
</transformers> | ||
<filters> | ||
<filter> | ||
<artifact>*:*</artifact> | ||
<excludes> | ||
<exclude>META-INF/*.SF</exclude> | ||
<exclude>META-INF/*.DSA</exclude> | ||
<exclude>META-INF/*.RSA</exclude> | ||
</excludes> | ||
</filter> | ||
</filters> | ||
<finalName>mcloud-node-agent</finalName> | ||
</configuration> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-compiler-plugin</artifactId> | ||
<version>${maven-compiler-plugin.version}</version> | ||
<configuration> | ||
<source>11</source> | ||
<target>11</target> | ||
</configuration> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
</project> |
53 changes: 53 additions & 0 deletions
53
agent/src/main/java/com/zebrunner/mcloud/grid/agent/NodeAgent.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,53 @@ | ||
package com.zebrunner.mcloud.grid.agent; | ||
|
||
import net.bytebuddy.agent.builder.AgentBuilder; | ||
import net.bytebuddy.description.method.MethodDescription; | ||
import net.bytebuddy.description.type.TypeDescription; | ||
import net.bytebuddy.dynamic.DynamicType; | ||
import net.bytebuddy.matcher.ElementMatcher; | ||
import net.bytebuddy.matcher.NameMatcher; | ||
import net.bytebuddy.pool.TypePool; | ||
|
||
import java.lang.instrument.Instrumentation; | ||
import java.util.logging.Logger; | ||
|
||
import static net.bytebuddy.implementation.MethodDelegation.to; | ||
import static net.bytebuddy.matcher.ElementMatchers.isPublic; | ||
import static net.bytebuddy.matcher.ElementMatchers.isStatic; | ||
import static net.bytebuddy.matcher.ElementMatchers.named; | ||
import static net.bytebuddy.matcher.ElementMatchers.not; | ||
|
||
public class NodeAgent { | ||
private static final Logger LOGGER = Logger.getLogger(NodeAgent.class.getName()); | ||
private static final String RELAY_SESSION_FACTORY_CLASS = "org.openqa.selenium.grid.node.relay.RelaySessionFactory"; | ||
private static final String TEST_METHOD_NAME = "test"; | ||
|
||
public static void premain(String args, Instrumentation instrumentation) { | ||
try { | ||
new AgentBuilder.Default() | ||
.with(new AgentBuilder.InitializationStrategy.SelfInjection.Eager()) | ||
.type(named(RELAY_SESSION_FACTORY_CLASS)) | ||
.transform((builder, type, classloader, module, protectionDomain) -> addTestMethodInterceptor(builder)) | ||
.installOn(instrumentation); | ||
} catch (Exception e) { | ||
LOGGER.warning(() -> "Could not init instrumentation."); | ||
} | ||
} | ||
|
||
private static DynamicType.Builder<?> addTestMethodInterceptor(DynamicType.Builder<?> builder) { | ||
return builder.method(isTestMethod()) | ||
.intercept(to(testMethodInterceptor())); | ||
} | ||
|
||
public static ElementMatcher<? super MethodDescription> isTestMethod() { | ||
return isPublic() | ||
.and(not(isStatic())) | ||
.and(new NameMatcher<>(TEST_METHOD_NAME::equals)); | ||
} | ||
|
||
private static TypeDescription testMethodInterceptor() { | ||
return TypePool.Default.ofSystemLoader() | ||
.describe(RelaySessionFactoryInterceptor.class.getName()) | ||
.resolve(); | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
agent/src/main/java/com/zebrunner/mcloud/grid/agent/RelaySessionFactoryInterceptor.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,16 @@ | ||
package com.zebrunner.mcloud.grid.agent; | ||
|
||
import net.bytebuddy.implementation.bind.annotation.RuntimeType; | ||
import net.bytebuddy.implementation.bind.annotation.SuperCall; | ||
import net.bytebuddy.implementation.bind.annotation.This; | ||
|
||
import java.util.concurrent.Callable; | ||
|
||
public class RelaySessionFactoryInterceptor { | ||
|
||
@RuntimeType | ||
public static Object onTestMethodInvocation(@This final Object factory, | ||
@SuperCall final Callable<Object> proxy) throws Exception { | ||
return true; | ||
} | ||
} |
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,4 @@ | ||
Manifest-Version: 1.0 | ||
Premain-Class: com.zebrunner.mcloud.grid.agent.NodeAgent | ||
Can-Redefine-Classes: true | ||
Can-Retransform-Classes: true |
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
Oops, something went wrong.