-
Notifications
You must be signed in to change notification settings - Fork 147
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into edeleon/nr-80764
- Loading branch information
Showing
85 changed files
with
4,045 additions
and
199 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
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
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
agent-bridge/src/test/java/com/newrelic/agent/bridge/AgentBridgeTest.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 com.newrelic.agent.bridge; | ||
|
||
|
||
import com.newrelic.api.agent.weaver.internal.WeavePackageType; | ||
import org.junit.Test; | ||
import org.mockito.Mockito; | ||
|
||
import java.util.concurrent.atomic.AtomicInteger; | ||
|
||
import static org.junit.Assert.*; | ||
public class AgentBridgeTest { | ||
@Test | ||
public void distributedTraceParseInstance_returnsNull() { | ||
assertNull(AgentBridge.distributedTraceParser.parseDistributedTracePayload("foo")); | ||
} | ||
|
||
@Test | ||
public void getAgent_returnsNoOpAgent() { | ||
assertEquals(NoOpAgent.INSTANCE, AgentBridge.getAgent()); | ||
} | ||
|
||
@Test | ||
public void extensionHolderFactoryInstance_returnsNoOpInstance() { | ||
assertEquals(ExtensionHolderFactory.NoOpExtensionHolderFactory.class, AgentBridge.extensionHolderFactory.getClass()); | ||
} | ||
|
||
@Test | ||
public void testCurrentApiSourceThreadLocalInstance() { | ||
|
||
ThreadLocal<WeavePackageType> instance = AgentBridge.currentApiSource; | ||
|
||
instance.set(WeavePackageType.FIELD); | ||
assertEquals(WeavePackageType.FIELD, instance.get()); | ||
|
||
instance.remove(); | ||
assertEquals(WeavePackageType.UNKNOWN, instance.get()); | ||
|
||
instance.set(null); | ||
assertEquals(WeavePackageType.UNKNOWN, instance.get()); | ||
} | ||
|
||
@Test | ||
public void testTokenAndRefCount() { | ||
Token mockToken = Mockito.mock(Token.class); | ||
TracedMethod mockTracedMethod = Mockito.mock(TracedMethod.class); | ||
AgentBridge.TokenAndRefCount instance = new AgentBridge.TokenAndRefCount(mockToken, mockTracedMethod, new AtomicInteger(1)); | ||
|
||
assertEquals(mockToken, instance.token); | ||
assertEquals(mockTracedMethod, instance.tracedMethod.get()); | ||
assertEquals(1, instance.refCount.get()); | ||
|
||
instance = new AgentBridge.TokenAndRefCount(null, mockTracedMethod, new AtomicInteger(1)); | ||
assertEquals(NoOpToken.INSTANCE, instance.token); | ||
|
||
// Just to get a coverage hit | ||
ThreadLocal<AgentBridge.TokenAndRefCount> dummy = AgentBridge.activeToken; | ||
|
||
|
||
} | ||
} |
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
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
116 changes: 116 additions & 0 deletions
116
.../src/test/java/com/newrelic/agent/introspec/internal/IntrospectorInsightsServiceTest.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,116 @@ | ||
package com.newrelic.agent.introspec.internal; | ||
|
||
import com.newrelic.agent.introspec.Event; | ||
import org.junit.Test; | ||
|
||
import java.util.Collection; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
import static org.junit.Assert.assertFalse; | ||
import static org.junit.Assert.assertNotNull; | ||
import static org.junit.Assert.assertTrue; | ||
|
||
public class IntrospectorInsightsServiceTest { | ||
@Test | ||
public void getName_returnsServiceName() { | ||
IntrospectorInsightsService introspectorInsightsService = new IntrospectorInsightsService(); | ||
assertEquals("InsightsService", introspectorInsightsService.getName()); | ||
} | ||
|
||
@Test | ||
public void controlMethods_behaveProperly() throws Exception { | ||
IntrospectorInsightsService introspectorInsightsService = new IntrospectorInsightsService(); | ||
|
||
introspectorInsightsService.start(); //No op | ||
introspectorInsightsService.stop(); //No op | ||
|
||
assertTrue(introspectorInsightsService.isEnabled()); | ||
assertTrue(introspectorInsightsService.isStarted()); | ||
assertTrue(introspectorInsightsService.isStartedOrStarting()); | ||
assertFalse(introspectorInsightsService.isStopped()); | ||
assertFalse(introspectorInsightsService.isStoppedOrStopping()); | ||
} | ||
|
||
@Test | ||
public void getLogger_returnsLoggerInstance() { | ||
IntrospectorInsightsService introspectorInsightsService = new IntrospectorInsightsService(); | ||
|
||
assertNotNull(introspectorInsightsService.getLogger()); | ||
} | ||
|
||
@Test | ||
public void recordCustomEvent_storeSuppliedLogEvent() { | ||
IntrospectorInsightsService introspectorInsightsService = new IntrospectorInsightsService(); | ||
Map<String, String> attributes = new HashMap<>(); | ||
attributes.put("key1", "val1"); | ||
attributes.put("key2", "val2"); | ||
|
||
introspectorInsightsService.recordCustomEvent("event", attributes); | ||
Collection<Event> events = introspectorInsightsService.getEvents("event"); | ||
|
||
assertEquals(1, events.size()); | ||
assertEquals(2, events.iterator().next().getAttributes().size()); | ||
} | ||
|
||
@Test | ||
public void getEventTypes_returnsStoredEventTypes() { | ||
IntrospectorInsightsService introspectorInsightsService = new IntrospectorInsightsService(); | ||
Map<String, String> attributes = new HashMap<>(); | ||
|
||
introspectorInsightsService.recordCustomEvent("event", attributes); | ||
introspectorInsightsService.recordCustomEvent("event2", attributes); | ||
Collection<String> events = introspectorInsightsService.getEventTypes(); | ||
|
||
assertEquals(2, events.size()); | ||
assertTrue(events.contains("event")); | ||
assertTrue(events.contains("event2")); | ||
} | ||
|
||
@Test | ||
public void clearMethods_clearEventReservoir() { | ||
IntrospectorInsightsService introspectorInsightsService = new IntrospectorInsightsService(); | ||
Map<String, String> attributes = new HashMap<>(); | ||
|
||
introspectorInsightsService.recordCustomEvent("event", attributes); | ||
Collection<Event> events = introspectorInsightsService.getEvents("event"); | ||
assertEquals(1, events.size()); | ||
|
||
introspectorInsightsService.clear(); | ||
events = introspectorInsightsService.getEvents("event"); | ||
assertEquals(0, events.size()); | ||
|
||
introspectorInsightsService.recordCustomEvent("event", attributes); | ||
events = introspectorInsightsService.getEvents("event"); | ||
assertEquals(1, events.size()); | ||
|
||
introspectorInsightsService.clearReservoir(); | ||
events = introspectorInsightsService.getEvents("event"); | ||
assertEquals(0, events.size()); | ||
} | ||
|
||
@Test | ||
public void getEventHarvestIntervalMetric_returnsEmptyString() { | ||
IntrospectorInsightsService introspectorInsightsService = new IntrospectorInsightsService(); | ||
assertEquals("", introspectorInsightsService.getEventHarvestIntervalMetric()); | ||
} | ||
|
||
@Test | ||
public void getReportPeriodInSecondsMetric_returnsEmptyString() { | ||
IntrospectorInsightsService introspectorInsightsService = new IntrospectorInsightsService(); | ||
assertEquals("", introspectorInsightsService.getReportPeriodInSecondsMetric()); | ||
} | ||
|
||
@Test | ||
public void getEventHarvestLimitMetric_returnsEmptyString() { | ||
IntrospectorInsightsService introspectorInsightsService = new IntrospectorInsightsService(); | ||
assertEquals("", introspectorInsightsService.getEventHarvestLimitMetric()); | ||
} | ||
|
||
@Test | ||
public void getMaxSamplesStored_returnsZero() { | ||
IntrospectorInsightsService introspectorInsightsService = new IntrospectorInsightsService(); | ||
assertEquals(0, introspectorInsightsService.getMaxSamplesStored()); | ||
} | ||
} |
Oops, something went wrong.