-
Notifications
You must be signed in to change notification settings - Fork 123
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add mock modules and use to test async plugin (#168)
- Loading branch information
1 parent
07dd271
commit 5768c27
Showing
29 changed files
with
1,103 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,44 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!-- | ||
~ Copyright (c) 2021, MegaEase | ||
~ All rights reserved. | ||
~ | ||
~ Licensed under the Apache License, Version 2.0 (the "License"); | ||
~ you may not use this file except in compliance with the License. | ||
~ You may obtain a copy of the License at | ||
~ | ||
~ http://www.apache.org/licenses/LICENSE-2.0 | ||
~ | ||
~ Unless required by applicable law or agreed to in writing, software | ||
~ distributed under the License is distributed on an "AS IS" BASIS, | ||
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
~ See the License for the specific language governing permissions and | ||
~ limitations under the License. | ||
--> | ||
|
||
<project xmlns="http://maven.apache.org/POM/4.0.0" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<parent> | ||
<artifactId>mock</artifactId> | ||
<groupId>com.megaease.easeagent</groupId> | ||
<version>2.0.0</version> | ||
</parent> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<artifactId>config-mock</artifactId> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>com.megaease.easeagent</groupId> | ||
<artifactId>config</artifactId> | ||
<version>${project.version}</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.megaease.easeagent</groupId> | ||
<artifactId>log4j2-mock</artifactId> | ||
<version>${project.version}</version> | ||
</dependency> | ||
</dependencies> | ||
|
||
</project> |
54 changes: 54 additions & 0 deletions
54
mock/config-mock/src/main/java/com/megaease/easeagent/mock/config/ConfigMock.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,54 @@ | ||
/* | ||
* Copyright (c) 2021, MegaEase | ||
* All rights reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.megaease.easeagent.mock.config; | ||
|
||
import com.megaease.easeagent.config.ConfigFactory; | ||
import com.megaease.easeagent.config.Configs; | ||
|
||
import java.io.File; | ||
import java.net.URL; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
public class ConfigMock { | ||
private static final String MOCK_CONFIG_FILE = "mock_agent.properties"; | ||
private static final Configs CONFIGS; | ||
|
||
static { | ||
Map<String, String> initConfigs = new HashMap<>(); | ||
initConfigs.put("name", "demo-service"); | ||
initConfigs.put("system", "demo-system"); | ||
|
||
initConfigs.put("observability.outputServer.timeout", "10000"); | ||
initConfigs.put("observability.outputServer.enabled", "true"); | ||
initConfigs.put("observability.tracings.output.enabled", "true"); | ||
initConfigs.put("plugin.observability.global.tracing.enabled", "true"); | ||
initConfigs.put("plugin.observability.global.metric.enabled", "true"); | ||
CONFIGS = new Configs(initConfigs); | ||
ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); | ||
URL url = classLoader.getResource(MOCK_CONFIG_FILE); | ||
if (url != null) { | ||
Configs configsFromOuterFile = ConfigFactory.loadFromFile(new File(url.getFile())); | ||
CONFIGS.updateConfigsNotNotify(configsFromOuterFile.getConfigs()); | ||
} | ||
} | ||
|
||
public static Configs getCONFIGS() { | ||
return CONFIGS; | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
mock/config-mock/src/test/java/com/megaease/easeagent/mock/config/ConfigMockTest.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,32 @@ | ||
/* | ||
* Copyright (c) 2021, MegaEase | ||
* All rights reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.megaease.easeagent.mock.config; | ||
|
||
import org.junit.Test; | ||
|
||
import static org.junit.Assert.*; | ||
|
||
public class ConfigMockTest { | ||
|
||
@Test | ||
public void getCONFIGS() { | ||
assertTrue(ConfigMock.getCONFIGS().getBoolean("test.mock.key")); | ||
assertEquals(ConfigMock.getCONFIGS().getString("test.mock.keyStr"), "testValue"); | ||
assertNull(ConfigMock.getCONFIGS().getString("test.mock.keyStrAAAAAAAAAA")); | ||
} | ||
} |
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,2 @@ | ||
test.mock.key=true | ||
test.mock.keyStr=testValue |
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,49 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!-- | ||
~ Copyright (c) 2021, MegaEase | ||
~ All rights reserved. | ||
~ | ||
~ Licensed under the Apache License, Version 2.0 (the "License"); | ||
~ you may not use this file except in compliance with the License. | ||
~ You may obtain a copy of the License at | ||
~ | ||
~ http://www.apache.org/licenses/LICENSE-2.0 | ||
~ | ||
~ Unless required by applicable law or agreed to in writing, software | ||
~ distributed under the License is distributed on an "AS IS" BASIS, | ||
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
~ See the License for the specific language governing permissions and | ||
~ limitations under the License. | ||
--> | ||
|
||
<project xmlns="http://maven.apache.org/POM/4.0.0" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<parent> | ||
<artifactId>mock</artifactId> | ||
<groupId>com.megaease.easeagent</groupId> | ||
<version>2.0.0</version> | ||
</parent> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<artifactId>context-mock</artifactId> | ||
|
||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>com.megaease.easeagent</groupId> | ||
<artifactId>context</artifactId> | ||
<version>${project.version}</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.megaease.easeagent</groupId> | ||
<artifactId>config-mock</artifactId> | ||
<version>${project.version}</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.megaease.easeagent</groupId> | ||
<artifactId>utils-mock</artifactId> | ||
<version>${project.version}</version> | ||
</dependency> | ||
</dependencies> | ||
</project> |
63 changes: 63 additions & 0 deletions
63
mock/context-mock/src/main/java/com/megaease/easeagent/mock/context/ContextManagerMock.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,63 @@ | ||
/* | ||
* Copyright (c) 2021, MegaEase | ||
* All rights reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.megaease.easeagent.mock.context; | ||
|
||
import com.megaease.easeagent.context.ContextManager; | ||
import com.megaease.easeagent.mock.config.ConfigMock; | ||
import com.megaease.easeagent.mock.utils.MockProvider; | ||
import com.megaease.easeagent.plugin.api.Context; | ||
import com.megaease.easeagent.plugin.api.InitializeContext; | ||
import com.megaease.easeagent.plugin.api.metric.MetricProvider; | ||
import com.megaease.easeagent.plugin.api.trace.TracingProvider; | ||
import com.megaease.easeagent.plugin.bridge.EaseAgent; | ||
|
||
import java.util.Iterator; | ||
import java.util.ServiceLoader; | ||
|
||
public class ContextManagerMock { | ||
private static final ContextManager CONTEXT_MANAGER_MOCK = ContextManager.build(ConfigMock.getCONFIGS()); | ||
|
||
static { | ||
ServiceLoader<MockProvider> loader = ServiceLoader.load(MockProvider.class); | ||
Iterator<MockProvider> iterator = loader.iterator(); | ||
while (iterator.hasNext()) { | ||
MockProvider mockProvider = iterator.next(); | ||
Object o = mockProvider.get(); | ||
if (o == null) { | ||
continue; | ||
} | ||
if (o instanceof TracingProvider) { | ||
CONTEXT_MANAGER_MOCK.setTracing((TracingProvider) o); | ||
} else if (o instanceof MetricProvider) { | ||
CONTEXT_MANAGER_MOCK.setMetric((MetricProvider) o); | ||
} | ||
} | ||
} | ||
|
||
public static ContextManager getContextManagerMock() { | ||
return CONTEXT_MANAGER_MOCK; | ||
} | ||
|
||
public static Context getContext() { | ||
return EaseAgent.contextSupplier.get(); | ||
} | ||
|
||
public static InitializeContext getInitializeContext() { | ||
return EaseAgent.initializeContextSupplier.get(); | ||
} | ||
} |
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,49 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!-- | ||
~ Copyright (c) 2021, MegaEase | ||
~ All rights reserved. | ||
~ | ||
~ Licensed under the Apache License, Version 2.0 (the "License"); | ||
~ you may not use this file except in compliance with the License. | ||
~ You may obtain a copy of the License at | ||
~ | ||
~ http://www.apache.org/licenses/LICENSE-2.0 | ||
~ | ||
~ Unless required by applicable law or agreed to in writing, software | ||
~ distributed under the License is distributed on an "AS IS" BASIS, | ||
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
~ See the License for the specific language governing permissions and | ||
~ limitations under the License. | ||
--> | ||
|
||
<project xmlns="http://maven.apache.org/POM/4.0.0" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<parent> | ||
<artifactId>mock</artifactId> | ||
<groupId>com.megaease.easeagent</groupId> | ||
<version>2.0.0</version> | ||
</parent> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<artifactId>metrics-mock</artifactId> | ||
|
||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>com.megaease.easeagent</groupId> | ||
<artifactId>metrics</artifactId> | ||
<version>${project.version}</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.megaease.easeagent</groupId> | ||
<artifactId>report-mock</artifactId> | ||
<version>${project.version}</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.megaease.easeagent</groupId> | ||
<artifactId>utils-mock</artifactId> | ||
<version>${project.version}</version> | ||
</dependency> | ||
</dependencies> | ||
</project> |
56 changes: 56 additions & 0 deletions
56
mock/metrics-mock/src/main/java/com/megaease/easeagent/mock/metrics/MetricProviderMock.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,56 @@ | ||
/* | ||
* Copyright (c) 2021, MegaEase | ||
* All rights reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.megaease.easeagent.mock.metrics; | ||
|
||
import com.megaease.easeagent.metrics.MetricProvider; | ||
import com.megaease.easeagent.metrics.jvm.gc.JVMGCMetricV2; | ||
import com.megaease.easeagent.metrics.jvm.memory.JVMMemoryMetricV2; | ||
import com.megaease.easeagent.mock.config.ConfigMock; | ||
import com.megaease.easeagent.mock.report.ReportMock; | ||
import com.megaease.easeagent.mock.utils.MockProvider; | ||
|
||
public class MetricProviderMock implements MockProvider { | ||
private static final MetricProvider METRIC_PROVIDER = new MetricProvider(); | ||
private static final JVMGCMetricV2 JVMGC_METRIC_V_2; | ||
private static final JVMMemoryMetricV2 JVM_MEMORY_METRIC_V_2; | ||
|
||
static { | ||
METRIC_PROVIDER.setConfig(ConfigMock.getCONFIGS()); | ||
METRIC_PROVIDER.setAgentReport(ReportMock.getAgentReport()); | ||
JVMGC_METRIC_V_2 = METRIC_PROVIDER.jvmGcMetricV2(); | ||
JVM_MEMORY_METRIC_V_2 = METRIC_PROVIDER.jvmMemoryMetricV2(); | ||
} | ||
|
||
|
||
public static MetricProvider getMetricProvider() { | ||
return METRIC_PROVIDER; | ||
} | ||
|
||
public static JVMGCMetricV2 getJvmgcMetricV2() { | ||
return JVMGC_METRIC_V_2; | ||
} | ||
|
||
public static JVMMemoryMetricV2 getJvmMemoryMetricV2() { | ||
return JVM_MEMORY_METRIC_V_2; | ||
} | ||
|
||
@Override | ||
public Object get() { | ||
return METRIC_PROVIDER; | ||
} | ||
} |
1 change: 1 addition & 0 deletions
1
...-mock/src/main/resources/META-INF/services/com.megaease.easeagent.mock.utils.MockProvider
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 @@ | ||
com.megaease.easeagent.mock.metrics.MetricProviderMock |
Oops, something went wrong.