use of com.newrelic.agent.transport.DataSenderListener in project newrelic-java-agent by newrelic.
the class RPMServiceTest method doTestLaunchThenAddPort.
private void doTestLaunchThenAddPort() throws Exception {
final AtomicReference<CountDownLatch> connectLatch = new AtomicReference<>(new CountDownLatch(2));
final AtomicReference<CountDownLatch> shutdownLatch = new AtomicReference<>(new CountDownLatch(2));
IDataSenderFactory dataSenderFactory = new IDataSenderFactory() {
@Override
public DataSender create(DataSenderConfig config) {
return createMockDataSender(config);
}
@Override
public DataSender create(DataSenderConfig config, DataSenderListener dataSenderListener) {
return createMockDataSender(config);
}
private MockDataSender createMockDataSender(DataSenderConfig config) {
return new MockDataSender(config) {
@Override
public Map<String, Object> connect(Map<String, Object> startupOptions) throws Exception {
connectLatch.get().countDown();
return super.connect(startupOptions);
}
@Override
public void shutdown(long timeMillis) throws Exception {
shutdownLatch.get().countDown();
super.shutdown(timeMillis);
}
};
}
};
DataSenderFactory.setDataSenderFactory(dataSenderFactory);
List<String> appNames = singletonList("MyApplication");
RPMService svc = new RPMService(appNames, null, null, Collections.<AgentConnectionEstablishedListener>emptyList());
svc.start();
svc.launch();
assertEquals(1L, connectLatch.get().getCount());
assertEquals(2L, shutdownLatch.get().getCount());
ServiceFactory.getEnvironmentService().getEnvironment().setServerPort(8080);
connectLatch.get().await(30, TimeUnit.SECONDS);
assertEquals(0L, connectLatch.get().getCount());
assertEquals(1L, shutdownLatch.get().getCount());
svc.shutdown();
assertEquals(0L, shutdownLatch.get().getCount());
}
use of com.newrelic.agent.transport.DataSenderListener in project newrelic-java-agent by newrelic.
the class RPMServiceTest method doTestTracedErrorsSizeLimit.
private void doTestTracedErrorsSizeLimit() throws Exception {
List<String> appNames = new ArrayList<>(1);
appNames.add("MyApplication");
final AtomicInteger errorSentCount = new AtomicInteger(0);
RPMService svc = new RPMService(appNames, null, null, new DataSenderListener() {
@Override
public void dataSent(String method, String encoding, String uri, byte[] rawDataSent) {
if (method.equals("error_data")) {
errorSentCount.incrementAndGet();
// Check that the raw data sent is less than the collector limit of 1MB (1000000 bytes)
assertTrue(rawDataSent.length < 1000000);
}
}
@Override
public void dataReceived(String method, String encoding, String uri, Map<?, ?> rawDataReceived) {
if (method.equals("error_data")) {
// The collector should let us know it only recieved 2 error traces (instead of 5)
assertEquals(2L, rawDataReceived.get("return_value"));
}
}
}, Collections.<AgentConnectionEstablishedListener>emptyList());
((MockRPMServiceManager) ServiceFactory.getRPMServiceManager()).setRPMService(svc);
svc.launch();
// are big enough to push the final traced error over the limit and thus prevent it from being sent.
for (int i = 0; i < 5; i++) {
// Each of these adds 249090 bytes, so we can successfully store 4 (996360 bytes -- 996468 with padding)
// but the 5th should push it over the limit so we will end up cutting the array in half
// (which rounds down to 2 elements).
svc.getErrorService().reportError(new LargeStackThrowableError(null, "", new Exception("Test"), System.currentTimeMillis(), null, null, null, null, null, 97500));
}
StatsEngineImpl harvestStatsEngine = new StatsEngineImpl();
((ErrorServiceImpl) svc.getErrorService()).harvestTracedErrors("MyApplication", harvestStatsEngine);
// This will collect the traced errors
svc.harvest(harvestStatsEngine);
Thread.sleep(500);
// one set of errors should get sent because the first will error out
assertEquals(1, errorSentCount.get());
svc.shutdown();
}
Aggregations