提交 a6b6899b 编写于 作者: P pengys5

SpiTest

上级 1a4a137f
package com.a.eye.skywalking.collector.actor;
import akka.actor.UntypedActor;
/**
* @author pengys5
*/
public abstract class AbstractWorker extends UntypedActor {
}
......@@ -16,6 +16,7 @@ public abstract class AbstractWorkerProvider {
public abstract int workerNum();
public void createWorker(ActorSystem system) {
System.out.println("workerName: " + workerName());
if (StringUtil.isEmpty(workerName())) {
throw new IllegalArgumentException("cannot createWorker() with anything not obtained from workerName()");
}
......
......@@ -5,8 +5,8 @@ import akka.actor.ActorSystem;
/**
* @author pengys5
*/
public class CollectorBoot {
public class CollectorBootstrap {
public static void main(String[] args) {
ActorSystem system = ActorSystem.create("ClusterSystem", config);
// ActorSystem system = ActorSystem.create("ClusterSystem", config);
}
}
package com.a.eye.skywalking.collector.actor;
/**
* Created by pengys5 on 2017/2/22 0022.
*/
public class CollectorConfig {
public static final String appname = "CollectorSystem";
public static class Collector {
public static String hostname = "127.0.0.1";
public static String port = "2551";
public static String cluster = "127.0.0.1:2551";
public static class Worker {
public static int ApplicationDiscoverMetric_Num = 2;
}
}
}
package com.a.eye.skywalking.collector.actor;
import com.a.eye.skywalking.api.logging.api.ILog;
import com.a.eye.skywalking.api.logging.api.LogManager;
import com.a.eye.skywalking.api.util.ConfigInitializer;
import com.a.eye.skywalking.api.util.StringUtil;
import java.io.InputStream;
import java.util.Properties;
/**
* @author pengys5
*/
public class CollectorConfigInitializer {
private static ILog logger = LogManager.getLogger(CollectorConfigInitializer.class);
public static void initialize() {
InputStream configFileStream = CollectorConfigInitializer.class.getResourceAsStream("/collector.config");
if (configFileStream == null) {
logger.info("Not provide sky-walking certification documents, sky-walking api run in default config.");
} else {
try {
Properties properties = new Properties();
properties.load(configFileStream);
ConfigInitializer.initialize(properties, CollectorConfig.class);
} catch (Exception e) {
logger.error("Failed to read the config file, sky-walking api run in default config.", e);
}
}
if (!StringUtil.isEmpty(System.getProperty("collector.hostname"))) {
CollectorConfig.Collector.hostname = System.getProperty("collector.hostname");
}
if (!StringUtil.isEmpty(System.getProperty("collector.port"))) {
CollectorConfig.Collector.port = System.getProperty("collector.port");
}
if (!StringUtil.isEmpty(System.getProperty("collector.cluster"))) {
CollectorConfig.Collector.cluster = System.getProperty("collector.cluster");
}
}
}
package com.a.eye.skywalking.collector.actor;
import akka.actor.ActorSystem;
import java.util.ServiceLoader;
/**
* @author pengys5
*/
public enum WorkersCreator {
INSTANCE;
public void boot(ActorSystem system) {
ServiceLoader<AbstractWorkerProvider> serviceLoader = ServiceLoader.load(AbstractWorkerProvider.class);
for (AbstractWorkerProvider provider : serviceLoader) {
provider.createWorker(system);
}
}
}
package com.a.eye.skywalking.collector.actor;
/**
* @author pengys5
*/
public class SpiTestWorker extends AbstractWorker {
@Override
public void onReceive(Object message) throws Throwable {
}
}
package com.a.eye.skywalking.collector.actor;
/**
* @author pengys5
*/
public class SpiTestWorkerFactory extends AbstractWorkerProvider {
public static final String WorkerName = "SpiTestWorker";
@Override
public String workerName() {
return WorkerName;
}
@Override
public Class workerClass() {
return SpiTestWorker.class;
}
@Override
public int workerNum() {
return 2;
}
}
package com.a.eye.skywalking.collector.actor;
import akka.actor.ActorSystem;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.mockito.Mockito;
/**
* @author pengys5
*/
public class SpiTestWorkerFactoryTestCase {
ActorSystem system;
@Before
public void createSystem() {
system = ActorSystem.create();
}
@After
public void terminateSystem() throws IllegalAccessException {
system.terminate();
system.awaitTermination();
system = null;
}
@Test
public void testWorkerCreate() {
SpiTestWorkerFactory factory = Mockito.mock(SpiTestWorkerFactory.class);
Mockito.when(factory.workerName()).thenReturn("");
factory.createWorker(system);
}
}
package com.a.eye.skywalking.collector.actor;
import akka.actor.ActorSystem;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
/**
* @author pengys5
*/
public class WorkersCreatorTestCase {
ActorSystem system;
@Before
public void createSystem() {
system = ActorSystem.create();
}
@After
public void terminateSystem() throws IllegalAccessException {
system.terminate();
system.awaitTermination();
system = null;
}
@Test
public void testBoot() {
WorkersCreator.INSTANCE.boot(system);
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册