modify testcase bug When errors occur in timezone
This commit is contained in:
parent
be626bdaae
commit
e9abfff154
|
|
@ -85,6 +85,7 @@ public class SegmentPost extends AbstractPost {
|
||||||
long hourSlice = DateTools.getHourSlice(newSegment.getStartTime());
|
long hourSlice = DateTools.getHourSlice(newSegment.getStartTime());
|
||||||
long daySlice = DateTools.getDaySlice(newSegment.getStartTime());
|
long daySlice = DateTools.getDaySlice(newSegment.getStartTime());
|
||||||
int second = DateTools.getSecond(newSegment.getStartTime());
|
int second = DateTools.getSecond(newSegment.getStartTime());
|
||||||
|
logger.debug("minuteSlice: %s, hourSlice: %s, daySlice: %s, second:%s", minuteSlice, hourSlice, daySlice, second);
|
||||||
|
|
||||||
SegmentWithTimeSlice segmentWithTimeSlice = new SegmentWithTimeSlice(newSegment, minuteSlice, hourSlice, daySlice, second);
|
SegmentWithTimeSlice segmentWithTimeSlice = new SegmentWithTimeSlice(newSegment, minuteSlice, hourSlice, daySlice, second);
|
||||||
String newSegmentJsonStr = gson.toJson(newSegment);
|
String newSegmentJsonStr = gson.toJson(newSegment);
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@ package com.a.eye.skywalking.collector.worker.tools;
|
||||||
|
|
||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
import java.util.Calendar;
|
import java.util.Calendar;
|
||||||
|
import java.util.TimeZone;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author pengys5
|
* @author pengys5
|
||||||
|
|
@ -19,7 +20,7 @@ public class DateTools {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static long getMinuteSlice(long time) {
|
public static long getMinuteSlice(long time) {
|
||||||
Calendar calendar = Calendar.getInstance();
|
Calendar calendar = Calendar.getInstance(TimeZone.getTimeZone("GMT+8:00"));
|
||||||
calendar.setTimeInMillis(time);
|
calendar.setTimeInMillis(time);
|
||||||
String timeStr = minuteDateFormat.format(calendar.getTime());
|
String timeStr = minuteDateFormat.format(calendar.getTime());
|
||||||
return Long.valueOf(timeStr);
|
return Long.valueOf(timeStr);
|
||||||
|
|
@ -38,4 +39,12 @@ public class DateTools {
|
||||||
String timeStr = dayDateFormat.format(calendar.getTime()) + "0000";
|
String timeStr = dayDateFormat.format(calendar.getTime()) + "0000";
|
||||||
return Long.valueOf(timeStr);
|
return Long.valueOf(timeStr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static long changeToUTCSlice(long timeSlice) {
|
||||||
|
if (TimeZone.getDefault().getID().equals("GMT+08:00")) {
|
||||||
|
return timeSlice;
|
||||||
|
} else {
|
||||||
|
return timeSlice - 800;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,7 +0,0 @@
|
||||||
package com.a.eye.skywalking.collector.worker;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author pengys5
|
|
||||||
*/
|
|
||||||
public class MergePersistenceMemberTestCase {
|
|
||||||
}
|
|
||||||
|
|
@ -14,6 +14,7 @@ import com.a.eye.skywalking.collector.worker.segment.mock.SegmentMock;
|
||||||
import com.a.eye.skywalking.collector.worker.segment.persistence.SegmentCostSave;
|
import com.a.eye.skywalking.collector.worker.segment.persistence.SegmentCostSave;
|
||||||
import com.a.eye.skywalking.collector.worker.segment.persistence.SegmentExceptionSave;
|
import com.a.eye.skywalking.collector.worker.segment.persistence.SegmentExceptionSave;
|
||||||
import com.a.eye.skywalking.collector.worker.segment.persistence.SegmentSave;
|
import com.a.eye.skywalking.collector.worker.segment.persistence.SegmentSave;
|
||||||
|
import com.a.eye.skywalking.collector.worker.tools.DateTools;
|
||||||
import com.google.gson.JsonObject;
|
import com.google.gson.JsonObject;
|
||||||
import org.junit.Assert;
|
import org.junit.Assert;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
|
|
@ -166,48 +167,48 @@ public class SegmentPostTestCase {
|
||||||
|
|
||||||
segmentPost.onReceive(cacheServiceSegmentAsString);
|
segmentPost.onReceive(cacheServiceSegmentAsString);
|
||||||
|
|
||||||
Assert.assertEquals(201703310915L, segmentSaveAnswer_1.minute);
|
Assert.assertEquals(DateTools.changeToUTCSlice(201703310915L), segmentSaveAnswer_1.minute);
|
||||||
Assert.assertEquals(201703310900L, segmentSaveAnswer_1.hour);
|
Assert.assertEquals(DateTools.changeToUTCSlice(201703310900L), segmentSaveAnswer_1.hour);
|
||||||
Assert.assertEquals(201703310000L, segmentSaveAnswer_1.day);
|
Assert.assertEquals(201703310000L, segmentSaveAnswer_1.day);
|
||||||
|
|
||||||
Assert.assertEquals(201703310915L, segmentSaveAnswer_2.minute);
|
Assert.assertEquals(DateTools.changeToUTCSlice(201703310915L), segmentSaveAnswer_2.minute);
|
||||||
Assert.assertEquals(201703310900L, segmentSaveAnswer_2.hour);
|
Assert.assertEquals(DateTools.changeToUTCSlice(201703310900L), segmentSaveAnswer_2.hour);
|
||||||
Assert.assertEquals(201703310000L, segmentSaveAnswer_2.day);
|
Assert.assertEquals(201703310000L, segmentSaveAnswer_2.day);
|
||||||
|
|
||||||
Assert.assertEquals(201703310915L, segmentCostSaveAnswer.segmentWithTimeSlice.getMinute());
|
Assert.assertEquals(DateTools.changeToUTCSlice(201703310915L), segmentCostSaveAnswer.segmentWithTimeSlice.getMinute());
|
||||||
Assert.assertEquals(201703310900L, segmentCostSaveAnswer.segmentWithTimeSlice.getHour());
|
Assert.assertEquals(DateTools.changeToUTCSlice(201703310900L), segmentCostSaveAnswer.segmentWithTimeSlice.getHour());
|
||||||
Assert.assertEquals(201703310000L, segmentCostSaveAnswer.segmentWithTimeSlice.getDay());
|
Assert.assertEquals(201703310000L, segmentCostSaveAnswer.segmentWithTimeSlice.getDay());
|
||||||
|
|
||||||
Assert.assertEquals(201703310915L, globalTraceAnalysisAnswer.segmentWithTimeSlice.getMinute());
|
Assert.assertEquals(DateTools.changeToUTCSlice(201703310915L), globalTraceAnalysisAnswer.segmentWithTimeSlice.getMinute());
|
||||||
Assert.assertEquals(201703310900L, globalTraceAnalysisAnswer.segmentWithTimeSlice.getHour());
|
Assert.assertEquals(DateTools.changeToUTCSlice(201703310900L), globalTraceAnalysisAnswer.segmentWithTimeSlice.getHour());
|
||||||
Assert.assertEquals(201703310000L, globalTraceAnalysisAnswer.segmentWithTimeSlice.getDay());
|
Assert.assertEquals(201703310000L, globalTraceAnalysisAnswer.segmentWithTimeSlice.getDay());
|
||||||
|
|
||||||
Assert.assertEquals(201703310915L, segmentExceptionSaveAnswer.segmentWithTimeSlice.getMinute());
|
Assert.assertEquals(DateTools.changeToUTCSlice(201703310915L), segmentExceptionSaveAnswer.segmentWithTimeSlice.getMinute());
|
||||||
Assert.assertEquals(201703310900L, segmentExceptionSaveAnswer.segmentWithTimeSlice.getHour());
|
Assert.assertEquals(DateTools.changeToUTCSlice(201703310900L), segmentExceptionSaveAnswer.segmentWithTimeSlice.getHour());
|
||||||
Assert.assertEquals(201703310000L, segmentExceptionSaveAnswer.segmentWithTimeSlice.getDay());
|
Assert.assertEquals(201703310000L, segmentExceptionSaveAnswer.segmentWithTimeSlice.getDay());
|
||||||
|
|
||||||
Assert.assertEquals(201703310915L, nodeRefMinuteAnalysisAnswer.segmentWithTimeSlice.getMinute());
|
Assert.assertEquals(DateTools.changeToUTCSlice(201703310915L), nodeRefMinuteAnalysisAnswer.segmentWithTimeSlice.getMinute());
|
||||||
Assert.assertEquals(201703310900L, nodeRefMinuteAnalysisAnswer.segmentWithTimeSlice.getHour());
|
Assert.assertEquals(DateTools.changeToUTCSlice(201703310900L), nodeRefMinuteAnalysisAnswer.segmentWithTimeSlice.getHour());
|
||||||
Assert.assertEquals(201703310000L, nodeRefMinuteAnalysisAnswer.segmentWithTimeSlice.getDay());
|
Assert.assertEquals(201703310000L, nodeRefMinuteAnalysisAnswer.segmentWithTimeSlice.getDay());
|
||||||
|
|
||||||
Assert.assertEquals(201703310915L, nodeRefHourAnalysisAnswer.segmentWithTimeSlice.getMinute());
|
Assert.assertEquals(DateTools.changeToUTCSlice(201703310915L), nodeRefHourAnalysisAnswer.segmentWithTimeSlice.getMinute());
|
||||||
Assert.assertEquals(201703310900L, nodeRefHourAnalysisAnswer.segmentWithTimeSlice.getHour());
|
Assert.assertEquals(DateTools.changeToUTCSlice(201703310900L), nodeRefHourAnalysisAnswer.segmentWithTimeSlice.getHour());
|
||||||
Assert.assertEquals(201703310000L, nodeRefHourAnalysisAnswer.segmentWithTimeSlice.getDay());
|
Assert.assertEquals(201703310000L, nodeRefHourAnalysisAnswer.segmentWithTimeSlice.getDay());
|
||||||
|
|
||||||
Assert.assertEquals(201703310915L, nodeRefDayAnalysisAnswer.segmentWithTimeSlice.getMinute());
|
Assert.assertEquals(DateTools.changeToUTCSlice(201703310915L), nodeRefDayAnalysisAnswer.segmentWithTimeSlice.getMinute());
|
||||||
Assert.assertEquals(201703310900L, nodeRefDayAnalysisAnswer.segmentWithTimeSlice.getHour());
|
Assert.assertEquals(DateTools.changeToUTCSlice(201703310900L), nodeRefDayAnalysisAnswer.segmentWithTimeSlice.getHour());
|
||||||
Assert.assertEquals(201703310000L, nodeRefDayAnalysisAnswer.segmentWithTimeSlice.getDay());
|
Assert.assertEquals(201703310000L, nodeRefDayAnalysisAnswer.segmentWithTimeSlice.getDay());
|
||||||
|
|
||||||
Assert.assertEquals(201703310915L, nodeMinuteAnalysisAnswer.segmentWithTimeSlice.getMinute());
|
Assert.assertEquals(DateTools.changeToUTCSlice(201703310915L), nodeMinuteAnalysisAnswer.segmentWithTimeSlice.getMinute());
|
||||||
Assert.assertEquals(201703310900L, nodeMinuteAnalysisAnswer.segmentWithTimeSlice.getHour());
|
Assert.assertEquals(DateTools.changeToUTCSlice(201703310900L), nodeMinuteAnalysisAnswer.segmentWithTimeSlice.getHour());
|
||||||
Assert.assertEquals(201703310000L, nodeMinuteAnalysisAnswer.segmentWithTimeSlice.getDay());
|
Assert.assertEquals(201703310000L, nodeMinuteAnalysisAnswer.segmentWithTimeSlice.getDay());
|
||||||
|
|
||||||
Assert.assertEquals(201703310915L, nodeHourAnalysisAnswer.segmentWithTimeSlice.getMinute());
|
Assert.assertEquals(DateTools.changeToUTCSlice(201703310915L), nodeHourAnalysisAnswer.segmentWithTimeSlice.getMinute());
|
||||||
Assert.assertEquals(201703310900L, nodeHourAnalysisAnswer.segmentWithTimeSlice.getHour());
|
Assert.assertEquals(DateTools.changeToUTCSlice(201703310900L), nodeHourAnalysisAnswer.segmentWithTimeSlice.getHour());
|
||||||
Assert.assertEquals(201703310000L, nodeHourAnalysisAnswer.segmentWithTimeSlice.getDay());
|
Assert.assertEquals(201703310000L, nodeHourAnalysisAnswer.segmentWithTimeSlice.getDay());
|
||||||
|
|
||||||
Assert.assertEquals(201703310915L, nodeDayAnalysisAnswer.segmentWithTimeSlice.getMinute());
|
Assert.assertEquals(DateTools.changeToUTCSlice(201703310915L), nodeDayAnalysisAnswer.segmentWithTimeSlice.getMinute());
|
||||||
Assert.assertEquals(201703310900L, nodeDayAnalysisAnswer.segmentWithTimeSlice.getHour());
|
Assert.assertEquals(DateTools.changeToUTCSlice(201703310900L), nodeDayAnalysisAnswer.segmentWithTimeSlice.getHour());
|
||||||
Assert.assertEquals(201703310000L, nodeDayAnalysisAnswer.segmentWithTimeSlice.getDay());
|
Assert.assertEquals(201703310000L, nodeDayAnalysisAnswer.segmentWithTimeSlice.getDay());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,28 @@
|
||||||
|
package com.a.eye.skywalking.collector.worker.tools;
|
||||||
|
|
||||||
|
import org.junit.Assert;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import java.util.TimeZone;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author pengys5
|
||||||
|
*/
|
||||||
|
public class DateToolsTestCase {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testUTCLocation() {
|
||||||
|
TimeZone.setDefault(TimeZone.getTimeZone("UTC"));
|
||||||
|
long timeSlice = 201703310915L;
|
||||||
|
long changedTimeSlice = DateTools.changeToUTCSlice(timeSlice);
|
||||||
|
Assert.assertEquals(201703310115L, changedTimeSlice);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testUTC8Location() {
|
||||||
|
TimeZone.setDefault(TimeZone.getTimeZone("GMT+08:00"));
|
||||||
|
long timeSlice = 201703310915L;
|
||||||
|
long changedTimeSlice = DateTools.changeToUTCSlice(timeSlice);
|
||||||
|
Assert.assertEquals(201703310915L, changedTimeSlice);
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue