-
Notifications
You must be signed in to change notification settings - Fork 879
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
ee09b87
commit 8b93008
Showing
6 changed files
with
102 additions
and
0 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,13 @@ | ||
plugins { | ||
id("otel.javaagent-instrumentation") | ||
} | ||
|
||
dependencies { | ||
// To be able to have it as part of agent, | ||
// this dependency needs to be added as "testInstrumentation", not as "testImplementation" | ||
testInstrumentation(project(":instrumentation:resources:library")) | ||
} | ||
|
||
otelJava { | ||
minJavaVersionSupported.set(JavaVersion.VERSION_18) | ||
} |
26 changes: 26 additions & 0 deletions
26
...src/test/java/io/opentelemetry/javaagent/tooling/inetaddress/InetAddressResolverTest.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 @@ | ||
/* | ||
* Copyright The OpenTelemetry Authors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package io.opentelemetry.javaagent.tooling.inetaddress; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
import java.net.InetAddress; | ||
import org.junit.jupiter.api.Test; | ||
|
||
public class InetAddressResolverTest { | ||
|
||
@Test | ||
void agentStartShouldNotTriggerLoadingCustomInetAddressResolvers() throws Exception { | ||
// Agent start should not trigger loading (and instantiating) custom InetAddress resolvers | ||
assertThat(TestAddressResolver.isInstantiated()).isFalse(); | ||
|
||
// Trigger loading (and instantiating) custom InetAddress resolvers manually | ||
InetAddress.getAllByName("test"); | ||
|
||
// Verify that custom InetAddress resolver loaded and instantiated | ||
assertThat(TestAddressResolver.isInstantiated()).isTrue(); | ||
} | ||
} |
39 changes: 39 additions & 0 deletions
39
...a18/src/test/java/io/opentelemetry/javaagent/tooling/inetaddress/TestAddressResolver.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,39 @@ | ||
/* | ||
* Copyright The OpenTelemetry Authors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package io.opentelemetry.javaagent.tooling.inetaddress; | ||
|
||
import java.net.InetAddress; | ||
import java.net.UnknownHostException; | ||
import java.net.spi.InetAddressResolver; | ||
import java.util.stream.Stream; | ||
|
||
public class TestAddressResolver implements InetAddressResolver { | ||
|
||
private static volatile boolean instantiated = false; | ||
|
||
@SuppressWarnings("StaticAssignmentInConstructor") | ||
public TestAddressResolver() { | ||
TestAddressResolver.instantiated = true; | ||
} | ||
|
||
public static boolean isInstantiated() { | ||
return instantiated; | ||
} | ||
|
||
@Override | ||
public Stream<InetAddress> lookupByName(String host, LookupPolicy lookupPolicy) | ||
throws UnknownHostException { | ||
if (host.equals("test")) { | ||
return Stream.of(InetAddress.getByAddress(new byte[] {127, 0, 0, 1})); | ||
} | ||
throw new UnknownHostException(); | ||
} | ||
|
||
@Override | ||
public String lookupByAddress(byte[] addr) { | ||
throw new UnsupportedOperationException(); | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
...test/java/io/opentelemetry/javaagent/tooling/inetaddress/TestAddressResolverProvider.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,22 @@ | ||
/* | ||
* Copyright The OpenTelemetry Authors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package io.opentelemetry.javaagent.tooling.inetaddress; | ||
|
||
import java.net.spi.InetAddressResolver; | ||
import java.net.spi.InetAddressResolverProvider; | ||
|
||
public class TestAddressResolverProvider extends InetAddressResolverProvider { | ||
|
||
@Override | ||
public InetAddressResolver get(Configuration configuration) { | ||
return new TestAddressResolver(); | ||
} | ||
|
||
@Override | ||
public String name() { | ||
return "Test Internet Address Resolver Provider"; | ||
} | ||
} |
1 change: 1 addition & 0 deletions
1
...ting-java18/src/test/resources/META-INF/services/java.net.spi.InetAddressResolverProvider
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 @@ | ||
io.opentelemetry.javaagent.tooling.inetaddress.TestAddressResolverProvider |
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