-
Notifications
You must be signed in to change notification settings - Fork 99
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
Showing
11 changed files
with
287 additions
and
11 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
30 changes: 30 additions & 0 deletions
30
...ntation-api/src/test/java/io/arex/inst/extension/matcher/SafeExtendsClassMatcherTest.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,30 @@ | ||
package io.arex.inst.extension.matcher; | ||
|
||
import static org.junit.jupiter.api.Assertions.*; | ||
|
||
import net.bytebuddy.description.type.TypeDescription; | ||
import net.bytebuddy.matcher.ElementMatcher; | ||
import net.bytebuddy.matcher.ElementMatchers; | ||
import org.junit.jupiter.api.Test; | ||
|
||
/** | ||
* @since 2024/1/12 | ||
*/ | ||
class SafeExtendsClassMatcherTest { | ||
|
||
@Test | ||
void extendsClass() { | ||
ElementMatcher.Junction<TypeDescription> matcher = SafeExtendsClassMatcher.extendsClass( | ||
ElementMatchers.is(SafeExtendsClassMatcher.class)); | ||
|
||
assertTrue(matcher.matches(TypeDescription.ForLoadedType.of(SafeExtendsClassMatcher.class))); | ||
} | ||
|
||
@Test | ||
void testExtendsClass() { | ||
ElementMatcher.Junction<TypeDescription> matcher = SafeExtendsClassMatcher.extendsClass( | ||
ElementMatchers.is(ElementMatcher.Junction.AbstractBase.class), true); | ||
|
||
assertTrue(matcher.matches(TypeDescription.ForLoadedType.of(SafeExtendsClassMatcher.class))); | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
...umentation-api/src/test/java/io/arex/inst/runtime/context/RepeatedCollectManagerTest.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,34 @@ | ||
package io.arex.inst.runtime.context; | ||
|
||
import static org.junit.jupiter.api.Assertions.*; | ||
|
||
import org.junit.jupiter.api.AfterAll; | ||
import org.junit.jupiter.api.BeforeAll; | ||
import org.junit.jupiter.api.Test; | ||
import org.mockito.Mockito; | ||
|
||
/** | ||
* @since 2024/1/12 | ||
*/ | ||
class RepeatedCollectManagerTest { | ||
@BeforeAll | ||
static void setUp() { | ||
Mockito.mockStatic(ContextManager.class); | ||
} | ||
@AfterAll | ||
static void tearDown() { | ||
Mockito.clearAllCaches(); | ||
} | ||
|
||
@Test | ||
void test() { | ||
assertTrue(RepeatedCollectManager.validate()); | ||
assertTrue(RepeatedCollectManager.exitAndValidate()); | ||
|
||
Mockito.when(ContextManager.needRecord()).thenReturn(true); | ||
RepeatedCollectManager.enter(); | ||
RepeatedCollectManager.enter(); | ||
assertFalse(RepeatedCollectManager.exitAndValidate()); | ||
assertTrue(RepeatedCollectManager.exitAndValidate()); | ||
} | ||
} |
45 changes: 45 additions & 0 deletions
45
arex-instrumentation-foundation/src/test/java/io/arex/foundation/util/NetUtilsTest.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,45 @@ | ||
package io.arex.foundation.util; | ||
|
||
import static org.junit.jupiter.api.Assertions.*; | ||
import static org.mockito.Mockito.mockStatic; | ||
|
||
import org.junit.jupiter.api.AfterEach; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
import org.mockito.MockedStatic; | ||
|
||
/** | ||
* @since 2024/1/12 | ||
*/ | ||
class NetUtilsTest { | ||
|
||
@BeforeEach | ||
void setUp() { | ||
} | ||
|
||
@AfterEach | ||
void tearDown() { | ||
} | ||
|
||
@Test | ||
void getIpAddress() { | ||
try (MockedStatic<NetUtils> netUtils = mockStatic(NetUtils.class)) { | ||
netUtils.when(NetUtils::getIpAddress).thenReturn("127.0.0.1"); | ||
assertEquals("127.0.0.1", NetUtils.getIpAddress()); | ||
} | ||
} | ||
|
||
@Test | ||
void checkTcpPortAvailable() { | ||
assertEquals(-1, NetUtils.checkTcpPortAvailable(1)); | ||
|
||
assertEquals(8080, NetUtils.checkTcpPortAvailable(8080)); | ||
} | ||
|
||
@Test | ||
void isTcpPortAvailable() { | ||
assertFalse(NetUtils.isTcpPortAvailable(1)); | ||
|
||
assertTrue(NetUtils.isTcpPortAvailable(8080)); | ||
} | ||
} |
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
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
60 changes: 60 additions & 0 deletions
60
...ion/redis/arex-redis-common/src/test/java/io/arex/inst/redis/common/RedisKeyUtilTest.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,60 @@ | ||
package io.arex.inst.redis.common; | ||
|
||
import static org.junit.jupiter.api.Assertions.*; | ||
|
||
import java.util.Arrays; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
import org.junit.jupiter.api.Test; | ||
|
||
/** | ||
* @since 2024/1/12 | ||
*/ | ||
class RedisKeyUtilTest { | ||
|
||
@Test | ||
void generateWithIterableKeys() { | ||
String result = RedisKeyUtil.generate(Arrays.asList("key1", "key2", "key3")); | ||
assertEquals("key1;key2;key3", result); | ||
} | ||
|
||
@Test | ||
void generateWithMapKeys() { | ||
Map<String, String> map = new HashMap<>(); | ||
map.put("key1", "value1"); | ||
map.put("key2", "value2"); | ||
String result = RedisKeyUtil.generate(map); | ||
assertTrue(result.contains("key1")); | ||
assertTrue(result.contains("key2")); | ||
} | ||
|
||
@Test | ||
void generateWithVarargsKeys() { | ||
String result = RedisKeyUtil.generate("key1", "key2", "key3"); | ||
assertEquals("key1;key2;key3", result); | ||
} | ||
|
||
@Test | ||
void generateWithEmptyVarargsKeys() { | ||
String result = RedisKeyUtil.generate(); | ||
assertEquals("", result); | ||
} | ||
|
||
@Test | ||
void generateWithSingleVarargsKey() { | ||
String result = RedisKeyUtil.generate("key1"); | ||
assertEquals("key1", result); | ||
} | ||
|
||
@Test | ||
void generateWithByteValue() { | ||
String result = RedisKeyUtil.generate(new byte[]{'k', 'e', 'y'}); | ||
assertEquals("key", result); | ||
} | ||
|
||
@Test | ||
void generateWithCharValue() { | ||
String result = RedisKeyUtil.generate(new char[]{'k', 'e', 'y'}); | ||
assertEquals("key", result); | ||
} | ||
} |
41 changes: 41 additions & 0 deletions
41
...machine/arex-time-machine/src/test/java/io/arex/inst/time/TimeMachineInterceptorTest.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,41 @@ | ||
package io.arex.inst.time; | ||
|
||
import static org.junit.jupiter.api.Assertions.*; | ||
|
||
import io.arex.agent.bootstrap.TraceContextManager; | ||
import io.arex.agent.bootstrap.cache.TimeCache; | ||
import org.junit.jupiter.api.AfterAll; | ||
import org.junit.jupiter.api.BeforeAll; | ||
import org.junit.jupiter.api.Test; | ||
import org.mockito.Mockito; | ||
|
||
/** | ||
* @since 2024/1/12 | ||
*/ | ||
class TimeMachineInterceptorTest { | ||
@BeforeAll | ||
static void setUp() { | ||
Mockito.mockStatic(TraceContextManager.class); | ||
} | ||
|
||
@AfterAll | ||
static void tearDown() { | ||
Mockito.clearAllCaches(); | ||
} | ||
|
||
@Test | ||
void onEnter() { | ||
// traceId is not null | ||
Mockito.when(TraceContextManager.get()).thenReturn("test"); | ||
assertEquals(0, TimeCache.get()); | ||
TimeCache.put(1L); | ||
assertNotEquals(0, TimeMachineInterceptor.onEnter()); | ||
} | ||
|
||
@Test | ||
void onExit() { | ||
long result = 456L; | ||
TimeMachineInterceptor.onExit(123L, result); | ||
assertEquals(456L, result); | ||
} | ||
} |
Oops, something went wrong.