use of com.navercorp.pinpoint.bootstrap.context.DatabaseInfo in project pinpoint by naver.
the class JDBCUrlParserTest method oracleParser2.
@Test
public void oracleParser2() {
// jdbc:oracle:thin:@hostname:port:SID
// "jdbc:oracle:thin:MYWORKSPACE/qwerty@localhost:1521:XE";
DatabaseInfo dbInfo = jdbcUrlParser.parse("jdbc:oracle:thin:MYWORKSPACE/qwerty@localhost:1521:XE");
Assert.assertTrue(dbInfo.isParsingComplete());
Assert.assertEquals(dbInfo.getType(), OracleConstants.ORACLE);
Assert.assertEquals(dbInfo.getHost().get(0), "localhost:1521");
Assert.assertEquals(dbInfo.getDatabaseId(), "XE");
Assert.assertEquals(dbInfo.getUrl(), "jdbc:oracle:thin:MYWORKSPACE/qwerty@localhost:1521:XE");
logger.info(dbInfo.toString());
}
use of com.navercorp.pinpoint.bootstrap.context.DatabaseInfo in project pinpoint by naver.
the class PostgreSqlUrlParserTest method parseFailTest1.
@Test
public void parseFailTest1() {
DatabaseInfo dbInfo = jdbcUrlParser.parse(null);
Assert.assertFalse(dbInfo.isParsingComplete());
Assert.assertEquals(ServiceType.UNKNOWN_DB, dbInfo.getType());
}
use of com.navercorp.pinpoint.bootstrap.context.DatabaseInfo in project pinpoint by naver.
the class DefaultDataSourceMetric method collectDataSource.
private TDataSource collectDataSource(DataSourceMonitorWrapper dataSourceMonitor) {
TDataSource dataSource = new TDataSource();
dataSource.setId(dataSourceMonitor.getId());
dataSource.setServiceTypeCode(dataSourceMonitor.getServiceType().getCode());
String jdbcUrl = dataSourceMonitor.getUrl();
if (jdbcUrl != null) {
dataSource.setUrl(jdbcUrl);
DatabaseInfo databaseInfo = jdbcUrlParsingService.getDatabaseInfo(jdbcUrl);
if (databaseInfo != null) {
dataSource.setDatabaseName(databaseInfo.getDatabaseId());
}
}
int activeConnectionSize = dataSourceMonitor.getActiveConnectionSize();
// this field is optional (default value is 0)
if (activeConnectionSize != 0) {
dataSource.setActiveConnectionSize(activeConnectionSize);
}
dataSource.setMaxConnectionSize(dataSourceMonitor.getMaxConnectionSize());
return dataSource;
}
use of com.navercorp.pinpoint.bootstrap.context.DatabaseInfo in project pinpoint by naver.
the class DefaultJdbcUrlParsingService method parseJdbcUrl.
@Override
public DatabaseInfo parseJdbcUrl(ServiceType serviceType, String jdbcUrl) {
if (jdbcUrl == null) {
return UnKnownDatabaseInfo.INSTANCE;
}
CacheKey cacheKey = new CacheKey(serviceType, jdbcUrl);
DatabaseInfo cacheValue = eachServiceTypeCache.get(cacheKey);
if (cacheValue != null) {
return cacheValue;
}
for (JdbcUrlParserV2 parser : jdbcUrlParserList) {
if (serviceType == parser.getServiceType()) {
DatabaseInfo databaseInfo = parser.parse(jdbcUrl);
return putCacheIfAbsent(cacheKey, databaseInfo);
}
}
return putCacheIfAbsent(cacheKey, UnKnownDatabaseInfo.createUnknownDataBase(jdbcUrl));
}
use of com.navercorp.pinpoint.bootstrap.context.DatabaseInfo in project pinpoint by naver.
the class AccessorInjectionTest method addTraceValue.
@Test
public void addTraceValue() throws Exception {
final TestClassLoader loader = getTestClassLoader();
final String javassistClassName = "com.navercorp.pinpoint.test.javasssit.mock.TestObject";
loader.addTransformer(javassistClassName, new TransformCallback() {
@Override
public byte[] doInTransform(Instrumentor instrumentor, ClassLoader loader, String className, Class<?> classBeingRedefined, ProtectionDomain protectionDomain, byte[] classfileBuffer) throws InstrumentException {
try {
logger.info("modify cl:{}", loader);
InstrumentClass aClass = instrumentor.getInstrumentClass(loader, javassistClassName, classfileBuffer);
aClass.addField(ObjectTraceValue.class.getName());
aClass.addField(IntTraceValue.class.getName());
aClass.addField(IntArrayTraceValue.class.getName());
aClass.addField(IntegerArrayTraceValue.class.getName());
aClass.addField(DatabaseInfoTraceValue.class.getName());
aClass.addField(BindValueTraceValue.class.getName());
String methodName = "callA";
aClass.getDeclaredMethod(methodName).addInterceptor("com.navercorp.pinpoint.test.javasssit.TestBeforeInterceptor");
return aClass.toBytecode();
} catch (InstrumentException e) {
e.printStackTrace();
throw new RuntimeException(e.getMessage(), e);
}
}
});
Class<?> testObjectClazz = loader.loadClass(javassistClassName);
final String methodName = "callA";
logger.info("class:{}", testObjectClazz.toString());
final Object testObject = testObjectClazz.newInstance();
Method callA = testObjectClazz.getMethod(methodName);
callA.invoke(testObject);
Class<?> objectTraceValue = loader.loadClass(ObjectTraceValue.class.getName());
Assert.assertTrue("ObjectTraceValue implements fail", objectTraceValue.isInstance(testObject));
objectTraceValue.getMethod("_$PINPOINT$_setTraceObject", Object.class).invoke(testObject, "a");
Object get = objectTraceValue.getMethod("_$PINPOINT$_getTraceObject").invoke(testObject);
Assert.assertEquals("a", get);
Class<?> intTraceValue = loader.loadClass(IntTraceValue.class.getName());
Assert.assertTrue("IntTraceValue implements fail", intTraceValue.isInstance(testObject));
intTraceValue.getMethod("_$PINPOINT$_setTraceInt", int.class).invoke(testObject, 1);
int a = (Integer) intTraceValue.getMethod("_$PINPOINT$_getTraceInt").invoke(testObject);
Assert.assertEquals(1, a);
Class<?> intArrayTraceValue = loader.loadClass(IntArrayTraceValue.class.getName());
Assert.assertTrue("IntArrayTraceValue implements fail", intArrayTraceValue.isInstance(testObject));
int[] expectedInts = { 1, 2, 3 };
intArrayTraceValue.getMethod("_$PINPOINT$_setTraceIntArray", int[].class).invoke(testObject, expectedInts);
int[] ints = (int[]) intArrayTraceValue.getMethod("_$PINPOINT$_getTraceIntArray").invoke(testObject);
Assert.assertEquals(expectedInts, ints);
Class<?> integerArrayTraceValue = loader.loadClass(IntegerArrayTraceValue.class.getName());
Assert.assertTrue("IntegerArrayTraceValue implements fail", integerArrayTraceValue.isInstance(testObject));
Integer[] expectedIntegers = { 1, 2 };
// wrap due to vararg expansion
Object[] wrappedExpectedIntegers = new Object[] { expectedIntegers };
integerArrayTraceValue.getMethod("_$PINPOINT$_setTraceIntegerArray", Integer[].class).invoke(testObject, wrappedExpectedIntegers);
Integer[] integers = (Integer[]) integerArrayTraceValue.getMethod("_$PINPOINT$_getTraceIntegerArray").invoke(testObject);
Assert.assertArrayEquals(expectedIntegers, integers);
Class<?> databaseTraceValue = loader.loadClass(DatabaseInfoTraceValue.class.getName());
Assert.assertTrue("DatabaseInfoTraceValue implements fail", databaseTraceValue.isInstance(testObject));
databaseTraceValue.getMethod("_$PINPOINT$_setTraceDatabaseInfo", DatabaseInfo.class).invoke(testObject, UnKnownDatabaseInfo.INSTANCE);
Object databaseInfo = databaseTraceValue.getMethod("_$PINPOINT$_getTraceDatabaseInfo").invoke(testObject);
Assert.assertSame(UnKnownDatabaseInfo.INSTANCE, databaseInfo);
}
Aggregations