提交agent-test工程
This commit is contained in:
parent
a6a25591cb
commit
88377b6889
|
|
@ -0,0 +1,37 @@
|
|||
<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">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<groupId>com.ai.cloud</groupId>
|
||||
<artifactId>skywalking-agent-test</artifactId>
|
||||
<version>1.0-Final</version>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<name>skywalking-agent-test</name>
|
||||
<url>http://maven.apache.org</url>
|
||||
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<version>3.8.1</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<!-- http://mvnrepository.com/artifact/org.apache.logging.log4j/log4j-core -->
|
||||
<dependency>
|
||||
<groupId>org.apache.logging.log4j</groupId>
|
||||
<artifactId>log4j-core</artifactId>
|
||||
<version>2.6</version>
|
||||
</dependency>
|
||||
<!-- http://mvnrepository.com/artifact/redis.clients/jedis -->
|
||||
<dependency>
|
||||
<groupId>redis.clients</groupId>
|
||||
<artifactId>jedis</artifactId>
|
||||
<version>2.8.1</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
|
|
@ -0,0 +1,20 @@
|
|||
package com.ai.cloud.skywalking.agent.test;
|
||||
|
||||
import com.ai.cloud.skywalking.agent.test.utils.JedisUtils;
|
||||
|
||||
/**
|
||||
* Created by xin on 16-6-3.
|
||||
*/
|
||||
public class AgentTest {
|
||||
|
||||
public static void main(String[] args) {
|
||||
System.out.println("Begin...");
|
||||
JedisUtils.setData("testKey1", "testKey2");
|
||||
|
||||
System.out.println("testKey1 = " + JedisUtils.getData("testKey1"));
|
||||
|
||||
JedisUtils.expire("testKey1");
|
||||
|
||||
System.out.println("End.....");
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,72 @@
|
|||
package com.ai.cloud.skywalking.agent.test.utils;
|
||||
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import redis.clients.jedis.Jedis;
|
||||
import redis.clients.jedis.JedisPool;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.util.Properties;
|
||||
|
||||
public class JedisUtils {
|
||||
private static JedisPool jedisPool;
|
||||
private static Logger logger = LogManager.getLogger(JedisUtils.class);
|
||||
|
||||
static {
|
||||
InputStream redisConfigFileStream = JedisUtils.class.getResourceAsStream("/redis.conf");
|
||||
Properties jedisConfig = new Properties();
|
||||
try {
|
||||
jedisConfig.load(redisConfigFileStream);
|
||||
} catch (Exception e) {
|
||||
System.err.print("Failed to load redis.conf");
|
||||
System.exit(-1);
|
||||
}
|
||||
|
||||
jedisPool = new JedisPool(jedisConfig.getProperty("redis.ip", "127.0.0.1"),
|
||||
Integer.parseInt(jedisConfig.getProperty("redis.port", "6379")));
|
||||
}
|
||||
|
||||
public static void setData(String key, String value) {
|
||||
Jedis jedis = null;
|
||||
try {
|
||||
jedis = jedisPool.getResource();
|
||||
jedis.set(key, value);
|
||||
} catch (Exception e) {
|
||||
logger.error("Failed to set data", e);
|
||||
} finally {
|
||||
if (jedis != null) {
|
||||
jedis.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static String getData(String key) {
|
||||
Jedis jedis = null;
|
||||
try {
|
||||
jedis = jedisPool.getResource();
|
||||
return jedis.get(key);
|
||||
} catch (Exception e) {
|
||||
logger.error("Failed to set data", e);
|
||||
} finally {
|
||||
if (jedis != null) {
|
||||
jedis.close();
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public static void expire(String key) {
|
||||
Jedis jedis = null;
|
||||
try {
|
||||
jedis = jedisPool.getResource();
|
||||
jedis.expire(key, 0);
|
||||
} catch (Exception e) {
|
||||
logger.error("Failed to set data", e);
|
||||
} finally {
|
||||
if (jedis != null) {
|
||||
jedis.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue