testcase
This commit is contained in:
parent
15684ea934
commit
c5eb330c1c
|
|
@ -1,9 +1,15 @@
|
|||
package com.a.eye.skywalking.collector.actor;
|
||||
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
/**
|
||||
* @author pengys5
|
||||
*/
|
||||
public abstract class AbstractWorker {
|
||||
|
||||
private final Logger logger;
|
||||
|
||||
private final LocalWorkerContext selfContext;
|
||||
|
||||
private final Role role;
|
||||
|
|
@ -14,6 +20,11 @@ public abstract class AbstractWorker {
|
|||
this.role = role;
|
||||
this.clusterContext = clusterContext;
|
||||
this.selfContext = selfContext;
|
||||
this.logger = LogManager.getFormatterLogger(role.roleName());
|
||||
}
|
||||
|
||||
final public Logger logger() {
|
||||
return logger;
|
||||
}
|
||||
|
||||
public abstract void preStart() throws ProviderNotFoundException;
|
||||
|
|
|
|||
|
|
@ -6,12 +6,16 @@ import com.a.eye.skywalking.collector.actor.Role;
|
|||
import com.a.eye.skywalking.collector.actor.WorkerRefs;
|
||||
import com.a.eye.skywalking.collector.worker.storage.RecordAnalysisData;
|
||||
import com.google.gson.JsonObject;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
/**
|
||||
* @author pengys5
|
||||
*/
|
||||
public abstract class RecordAnalysisMember extends AnalysisMember {
|
||||
|
||||
private Logger logger = LogManager.getFormatterLogger(RecordAnalysisMember.class);
|
||||
|
||||
private RecordAnalysisData recordAnalysisData = new RecordAnalysisData();
|
||||
|
||||
public RecordAnalysisMember(Role role, ClusterWorkerContext clusterContext, LocalWorkerContext selfContext) {
|
||||
|
|
@ -26,13 +30,12 @@ public abstract class RecordAnalysisMember extends AnalysisMember {
|
|||
return recordAnalysisData;
|
||||
}
|
||||
|
||||
@Override
|
||||
final protected void aggregation() throws Exception {
|
||||
@Override final protected void aggregation() throws Exception {
|
||||
getRecordAnalysisData().asMap().forEach((key, value) -> {
|
||||
try {
|
||||
aggWorkRefs().tell(value);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
logger.error(e);
|
||||
}
|
||||
});
|
||||
getRecordAnalysisData().asMap().clear();
|
||||
|
|
|
|||
|
|
@ -8,8 +8,6 @@ import com.a.eye.skywalking.collector.worker.storage.RecordData;
|
|||
import com.a.eye.skywalking.collector.worker.storage.RecordPersistenceData;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.elasticsearch.action.index.IndexRequestBuilder;
|
||||
import org.elasticsearch.client.Client;
|
||||
|
||||
|
|
@ -18,8 +16,6 @@ import org.elasticsearch.client.Client;
|
|||
*/
|
||||
public abstract class RecordPersistenceMember extends PersistenceMember<RecordPersistenceData, RecordData> {
|
||||
|
||||
private Logger logger = LogManager.getFormatterLogger(RecordPersistenceMember.class);
|
||||
|
||||
public RecordPersistenceMember(Role role, ClusterWorkerContext clusterContext, LocalWorkerContext selfContext) {
|
||||
super(role, clusterContext, selfContext);
|
||||
}
|
||||
|
|
@ -33,13 +29,13 @@ public abstract class RecordPersistenceMember extends PersistenceMember<RecordPe
|
|||
public void analyse(Object message) throws Exception {
|
||||
if (message instanceof RecordData) {
|
||||
RecordData recordData = (RecordData) message;
|
||||
logger.debug("setRecord: id: %s, data: %s", recordData.getId(), recordData.getRecord());
|
||||
logger().debug("setRecord: id: %s, data: %s", recordData.getId(), recordData.getRecord());
|
||||
RecordPersistenceData data = getPersistenceData();
|
||||
data.hold();
|
||||
data.getOrCreate(recordData.getId()).setRecord(recordData.getRecord());
|
||||
data.release();
|
||||
} else {
|
||||
logger.error("message unhandled");
|
||||
logger().error("message unhandled");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,41 @@
|
|||
package com.a.eye.skywalking.collector.worker;
|
||||
|
||||
import com.a.eye.skywalking.collector.worker.storage.RecordData;
|
||||
import com.a.eye.skywalking.collector.worker.storage.RecordPersistenceData;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.powermock.api.mockito.PowerMockito;
|
||||
import org.powermock.core.classloader.annotations.PrepareForTest;
|
||||
import org.powermock.modules.junit4.PowerMockRunner;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
/**
|
||||
* @author pengys5
|
||||
*/
|
||||
@RunWith(PowerMockRunner.class)
|
||||
@PrepareForTest(RecordPersistenceMember.class)
|
||||
public class RecordPersistenceMemberTestCase {
|
||||
|
||||
@Test
|
||||
public void analyse() throws Exception {
|
||||
RecordPersistenceMember member = PowerMockito.mock(RecordPersistenceMember.class, CALLS_REAL_METHODS);
|
||||
Logger logger = mock(Logger.class);
|
||||
when(member.logger()).thenReturn(logger);
|
||||
|
||||
RecordPersistenceData data = mock(RecordPersistenceData.class);
|
||||
RecordData recordData = new RecordData("test1");
|
||||
when(data.getOrCreate(anyString())).thenReturn(recordData);
|
||||
|
||||
when(member.getPersistenceData()).thenReturn(data);
|
||||
|
||||
RecordData recordData_1 = new RecordData("test2");
|
||||
member.analyse(recordData_1);
|
||||
|
||||
verify(data).hold();
|
||||
verify(data).release();
|
||||
|
||||
member.analyse(new Object());
|
||||
}
|
||||
}
|
||||
|
|
@ -1,5 +1,6 @@
|
|||
package com.a.eye.skywalking.collector.worker.globaltrace;
|
||||
|
||||
import com.a.eye.skywalking.collector.worker.config.EsConfig;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
|
|
@ -22,4 +23,10 @@ public class GlobalTraceIndexTestCase {
|
|||
GlobalTraceIndex index = new GlobalTraceIndex();
|
||||
Assert.assertEquals("{\"properties\":{\"subSegIds\":{\"type\":\"keyword\"}}}", index.createMappingBuilder().string());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void refreshInterval() {
|
||||
GlobalTraceIndex index = new GlobalTraceIndex();
|
||||
Assert.assertEquals(EsConfig.Es.Index.RefreshInterval.GlobalTraceIndex.VALUE.intValue(), index.refreshInterval());
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
package com.a.eye.skywalking.collector.worker.node;
|
||||
|
||||
import com.a.eye.skywalking.collector.worker.config.EsConfig;
|
||||
import java.io.IOException;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
|
@ -21,4 +22,10 @@ public class NodeCompIndexTestCase {
|
|||
NodeCompIndex index = new NodeCompIndex();
|
||||
Assert.assertEquals("{\"properties\":{\"name\":{\"type\":\"keyword\"},\"peers\":{\"type\":\"keyword\"},\"aggId\":{\"type\":\"keyword\"}}}", index.createMappingBuilder().string());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void refreshInterval() {
|
||||
NodeCompIndex index = new NodeCompIndex();
|
||||
Assert.assertEquals(EsConfig.Es.Index.RefreshInterval.NodeCompIndex.VALUE.intValue(), index.refreshInterval());
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
package com.a.eye.skywalking.collector.worker.node;
|
||||
|
||||
import com.a.eye.skywalking.collector.worker.config.EsConfig;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
|
|
@ -22,4 +23,10 @@ public class NodeMappingIndexTestCase {
|
|||
NodeMappingIndex index = new NodeMappingIndex();
|
||||
Assert.assertEquals("{\"properties\":{\"code\":{\"type\":\"string\",\"index\":\"not_analyzed\"},\"peers\":{\"type\":\"string\",\"index\":\"not_analyzed\"},\"aggId\":{\"type\":\"string\",\"index\":\"not_analyzed\"},\"timeSlice\":{\"type\":\"long\",\"index\":\"not_analyzed\"}}}", index.createMappingBuilder().string());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void refreshInterval() {
|
||||
NodeMappingIndex index = new NodeMappingIndex();
|
||||
Assert.assertEquals(EsConfig.Es.Index.RefreshInterval.NodeMappingIndex.VALUE.intValue(), index.refreshInterval());
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,11 +1,10 @@
|
|||
package com.a.eye.skywalking.collector.worker.noderef;
|
||||
|
||||
import com.a.eye.skywalking.collector.worker.globaltrace.GlobalTraceIndex;
|
||||
import com.a.eye.skywalking.collector.worker.config.EsConfig;
|
||||
import java.io.IOException;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* @author pengys5
|
||||
*/
|
||||
|
|
@ -23,4 +22,10 @@ public class NodeRefIndexTestCase {
|
|||
NodeRefIndex index = new NodeRefIndex();
|
||||
Assert.assertEquals("{\"properties\":{\"front\":{\"type\":\"keyword\"},\"frontIsRealCode\":{\"type\":\"boolean\",\"index\":\"not_analyzed\"},\"behind\":{\"type\":\"keyword\"},\"behindIsRealCode\":{\"type\":\"boolean\",\"index\":\"not_analyzed\"},\"aggId\":{\"type\":\"keyword\"},\"timeSlice\":{\"type\":\"long\",\"index\":\"not_analyzed\"}}}", index.createMappingBuilder().string());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void refreshInterval() {
|
||||
NodeRefIndex index = new NodeRefIndex();
|
||||
Assert.assertEquals(EsConfig.Es.Index.RefreshInterval.NodeRefIndex.VALUE.intValue(), index.refreshInterval());
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
package com.a.eye.skywalking.collector.worker.noderef;
|
||||
|
||||
import com.a.eye.skywalking.collector.worker.config.EsConfig;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
|
|
@ -22,4 +23,10 @@ public class NodeRefResSumIndexTestCase {
|
|||
NodeRefResSumIndex index = new NodeRefResSumIndex();
|
||||
Assert.assertEquals("{\"properties\":{\"oneSecondLess\":{\"type\":\"long\",\"index\":\"not_analyzed\"},\"threeSecondLess\":{\"type\":\"long\",\"index\":\"not_analyzed\"},\"fiveSecondLess\":{\"type\":\"long\",\"index\":\"not_analyzed\"},\"fiveSecondGreater\":{\"type\":\"long\",\"index\":\"not_analyzed\"},\"error\":{\"type\":\"long\",\"index\":\"not_analyzed\"},\"summary\":{\"type\":\"long\",\"index\":\"not_analyzed\"},\"aggId\":{\"type\":\"keyword\"},\"timeSlice\":{\"type\":\"long\",\"index\":\"not_analyzed\"}}}", index.createMappingBuilder().string());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void refreshInterval() {
|
||||
NodeRefResSumIndex index = new NodeRefResSumIndex();
|
||||
Assert.assertEquals(EsConfig.Es.Index.RefreshInterval.NodeRefResSumIndex.VALUE.intValue(), index.refreshInterval());
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,11 +1,10 @@
|
|||
package com.a.eye.skywalking.collector.worker.segment;
|
||||
|
||||
import com.a.eye.skywalking.collector.worker.globaltrace.GlobalTraceIndex;
|
||||
import com.a.eye.skywalking.collector.worker.config.EsConfig;
|
||||
import java.io.IOException;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* @author pengys5
|
||||
*/
|
||||
|
|
@ -23,4 +22,10 @@ public class SegmentCostIndexTestCase {
|
|||
SegmentCostIndex index = new SegmentCostIndex();
|
||||
Assert.assertEquals("{\"properties\":{\"segId\":{\"type\":\"keyword\"},\"startTime\":{\"type\":\"long\",\"index\":\"not_analyzed\"},\"END_TIME\":{\"type\":\"long\",\"index\":\"not_analyzed\"},\"operationName\":{\"type\":\"keyword\"},\"cost\":{\"type\":\"long\",\"index\":\"not_analyzed\"}}}", index.createMappingBuilder().string());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void refreshInterval() {
|
||||
SegmentCostIndex index = new SegmentCostIndex();
|
||||
Assert.assertEquals(EsConfig.Es.Index.RefreshInterval.SegmentCostIndex.VALUE.intValue(), index.refreshInterval());
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,11 +1,10 @@
|
|||
package com.a.eye.skywalking.collector.worker.segment;
|
||||
|
||||
import com.a.eye.skywalking.collector.worker.globaltrace.GlobalTraceIndex;
|
||||
import com.a.eye.skywalking.collector.worker.config.EsConfig;
|
||||
import java.io.IOException;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* @author pengys5
|
||||
*/
|
||||
|
|
@ -23,4 +22,10 @@ public class SegmentExceptionIndexTestCase {
|
|||
SegmentExceptionIndex index = new SegmentExceptionIndex();
|
||||
Assert.assertEquals("{\"properties\":{\"segId\":{\"type\":\"keyword\"},\"isError\":{\"type\":\"boolean\",\"index\":\"not_analyzed\"},\"errorKind\":{\"type\":\"keyword\"}}}", index.createMappingBuilder().string());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void refreshInterval() {
|
||||
SegmentExceptionIndex index = new SegmentExceptionIndex();
|
||||
Assert.assertEquals(EsConfig.Es.Index.RefreshInterval.SegmentExceptionIndex.VALUE.intValue(), index.refreshInterval());
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
package com.a.eye.skywalking.collector.worker.segment;
|
||||
|
||||
import com.a.eye.skywalking.collector.worker.config.EsConfig;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
|
|
@ -22,4 +23,10 @@ public class SegmentIndexTestCase {
|
|||
SegmentIndex index = new SegmentIndex();
|
||||
Assert.assertEquals("{\"properties\":{\"traceSegmentId\":{\"type\":\"keyword\"},\"startTime\":{\"type\":\"date\",\"index\":\"not_analyzed\"},\"endTime\":{\"type\":\"date\",\"index\":\"not_analyzed\"},\"applicationCode\":{\"type\":\"keyword\"},\"minute\":{\"type\":\"long\",\"index\":\"not_analyzed\"},\"hour\":{\"type\":\"long\",\"index\":\"not_analyzed\"},\"day\":{\"type\":\"long\",\"index\":\"not_analyzed\"}}}", index.createMappingBuilder().string());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void refreshInterval() {
|
||||
SegmentIndex index = new SegmentIndex();
|
||||
Assert.assertEquals(EsConfig.Es.Index.RefreshInterval.SegmentIndex.VALUE.intValue(), index.refreshInterval());
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,35 @@
|
|||
package com.a.eye.skywalking.collector.worker.segment.analysis;
|
||||
|
||||
import com.a.eye.skywalking.collector.actor.LocalSyncWorkerRef;
|
||||
import com.a.eye.skywalking.collector.actor.LocalWorkerContext;
|
||||
import com.a.eye.skywalking.collector.actor.WorkerNotFoundException;
|
||||
import com.a.eye.skywalking.collector.actor.WorkerRef;
|
||||
import com.a.eye.skywalking.collector.actor.WorkerRefs;
|
||||
import com.a.eye.skywalking.collector.worker.segment.persistence.SegmentCostSave;
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.List;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* @author pengys5
|
||||
*/
|
||||
public class SegmentCostAnalysisTestCase {
|
||||
|
||||
@Test
|
||||
public void aggWorkRefs() throws WorkerNotFoundException, NoSuchFieldException, IllegalAccessException {
|
||||
LocalWorkerContext localWorkerContext = new LocalWorkerContext();
|
||||
|
||||
WorkerRef workerRef = new LocalSyncWorkerRef(SegmentCostSave.Role.INSTANCE, null);
|
||||
localWorkerContext.put(workerRef);
|
||||
|
||||
SegmentCostAnalysis analysis = new SegmentCostAnalysis(SegmentCostAnalysis.Role.INSTANCE, null, localWorkerContext);
|
||||
WorkerRefs workerRefs = analysis.aggWorkRefs();
|
||||
|
||||
Field testAField = workerRefs.getClass().getDeclaredField("workerRefs");
|
||||
testAField.setAccessible(true);
|
||||
List<LocalSyncWorkerRef> list = (List<LocalSyncWorkerRef>)testAField.get(workerRefs);
|
||||
|
||||
Assert.assertEquals(workerRef, list.get(0));
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue