Skip to content

Commit fb8b719

Browse files
author
xuchang
committed
Release 3.4.1
1 parent 39127e0 commit fb8b719

22 files changed

+266
-62
lines changed

SensorsAnalyticsSDK/pom.xml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
<groupId>com.sensorsdata.analytics.javasdk</groupId>
1616
<name>SensorsAnalyticsSDK</name>
1717
<artifactId>SensorsAnalyticsSDK</artifactId>
18-
<version>3.4.0</version>
18+
<version>3.4.1</version>
1919
<description>The official Java SDK of Sensors Analytics</description>
2020
<url>http://sensorsdata.cn</url>
2121

@@ -55,6 +55,7 @@
5555
<junit.version>4.11</junit.version>
5656
<slf4j.version>1.7.25</slf4j.version>
5757
<slf4j-simple.version>1.6.6</slf4j-simple.version>
58+
<jetty.version>9.4.12.v20180830</jetty.version>
5859
</properties>
5960

6061
<dependencies>
@@ -91,6 +92,12 @@
9192
<version>${junit.version}</version>
9293
<scope>test</scope>
9394
</dependency>
95+
<dependency>
96+
<groupId>org.eclipse.jetty.websocket</groupId>
97+
<artifactId>websocket-server</artifactId>
98+
<version>${jetty.version}</version>
99+
<scope>test</scope>
100+
</dependency>
94101
</dependencies>
95102

96103
<build>

SensorsAnalyticsSDK/src/main/java/com/sensorsdata/analytics/javasdk/SensorsConst.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ private SensorsConst() {
1515
/**
1616
* 当前JDK版本号,注意要和pom文件里面的version保持一致
1717
*/
18-
public static final String SDK_VERSION = "3.4.0";
18+
public static final String SDK_VERSION = "3.4.1";
1919
/**
2020
* 当前语言类型
2121
*/

SensorsAnalyticsSDK/src/main/java/com/sensorsdata/analytics/javasdk/consumer/InnerLoggingConsumer.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -112,9 +112,6 @@ public synchronized void close() {
112112
log.info("Call close method.");
113113
}
114114

115-
public enum LogSplitMode {
116-
DAY, HOUR
117-
}
118115
}
119116

120117
interface LoggingFileWriter {
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package com.sensorsdata.analytics.javasdk.consumer;
2+
3+
public enum LogSplitMode {
4+
DAY, HOUR
5+
}

SensorsAnalyticsSDK/src/main/test/java/com.sensorsdata.analytics.javasdk/ConcurrentLoggingConsumerTest.java

Lines changed: 0 additions & 47 deletions
This file was deleted.
Lines changed: 142 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
1+
package com.sensorsdata.analytics.javasdk;
2+
3+
import static org.junit.Assert.assertEquals;
4+
import static org.junit.Assert.assertNotNull;
5+
import static org.junit.Assert.assertTrue;
6+
7+
import com.sensorsdata.analytics.javasdk.consumer.ConcurrentLoggingConsumer;
8+
import com.sensorsdata.analytics.javasdk.consumer.LogSplitMode;
9+
10+
import com.sensorsdata.analytics.javasdk.exceptions.InvalidArgumentException;
11+
import org.junit.Before;
12+
import org.junit.Test;
13+
14+
import java.lang.reflect.Field;
15+
import java.util.HashMap;
16+
import java.util.Map;
17+
18+
/**
19+
* ConcurrentLoggingConsumer 单测
20+
*
21+
* @author fangzhuo
22+
* @version 1.0.0
23+
* @since 2021/11/25 16:46
24+
*/
25+
public class ConcurrentLoggingConsumerTest {
26+
27+
private ConcurrentLoggingConsumer consumer;
28+
29+
private StringBuilder messageBuffer;
30+
31+
@Before
32+
public void init() throws NoSuchFieldException, IllegalAccessException {
33+
consumer = new ConcurrentLoggingConsumer("file.log");
34+
Field field = consumer.getClass().getSuperclass().getDeclaredField("messageBuffer");
35+
field.setAccessible(true);
36+
messageBuffer = (StringBuilder) field.get(consumer);
37+
}
38+
39+
@Test
40+
public void checkSendData() {
41+
assertEquals(0, messageBuffer.length());
42+
Map<String, Object> event = new HashMap<>();
43+
event.put("distinct_id", "12345");
44+
event.put("event", "test");
45+
event.put("type", "track");
46+
consumer.send(event);
47+
assertNotNull(messageBuffer);
48+
messageBuffer.setLength(0);
49+
}
50+
51+
@Test
52+
public void checkInit() {
53+
new ConcurrentLoggingConsumer("file.log");
54+
new ConcurrentLoggingConsumer("file.log", 30);
55+
new ConcurrentLoggingConsumer("file.log", "lock.name", 20);
56+
new ConcurrentLoggingConsumer("file.log", "lock.name", 20, LogSplitMode.DAY);
57+
assertTrue(true);
58+
}
59+
60+
@Test
61+
public void testInit01() throws InvalidArgumentException {
62+
consumer = new ConcurrentLoggingConsumer("test.log");
63+
SensorsAnalytics sa = new SensorsAnalytics(consumer);
64+
Map<String, Object> properties = new HashMap<>();
65+
properties.put("test", "test");
66+
properties.put("$project", "abc");
67+
properties.put("$token", "123");
68+
sa.track("123", true, "test", properties);
69+
}
70+
71+
@Test
72+
public void testInit02() throws InvalidArgumentException {
73+
consumer = new ConcurrentLoggingConsumer("test.log", 100);
74+
SensorsAnalytics sa = new SensorsAnalytics(consumer);
75+
Map<String, Object> properties = new HashMap<>();
76+
properties.put("test", "test");
77+
properties.put("$project", "abc");
78+
properties.put("$token", "123");
79+
sa.track("123", true, "test01", properties);
80+
sa.track("123", true, "test01", properties);
81+
}
82+
83+
@Test
84+
public void testInit03() throws InvalidArgumentException {
85+
consumer = new ConcurrentLoggingConsumer("test.log", "lock.log");
86+
SensorsAnalytics sa = new SensorsAnalytics(consumer);
87+
Map<String, Object> properties = new HashMap<>();
88+
properties.put("test", "test");
89+
properties.put("$project", "abc");
90+
properties.put("$token", "123");
91+
sa.track("123", true, "test01", properties);
92+
sa.track("123", true, "test01", properties);
93+
}
94+
95+
@Test
96+
public void testInit04() throws InvalidArgumentException {
97+
consumer = new ConcurrentLoggingConsumer("test.log", "lock.log", 100);
98+
SensorsAnalytics sa = new SensorsAnalytics(consumer);
99+
Map<String, Object> properties = new HashMap<>();
100+
properties.put("test", "test");
101+
properties.put("$project", "abc");
102+
properties.put("$token", "123");
103+
sa.track("123", true, "test01", properties);
104+
sa.track("123", true, "test01", properties);
105+
}
106+
107+
@Test
108+
public void testInit05() throws InvalidArgumentException {
109+
consumer = new ConcurrentLoggingConsumer("test.log", "lock.log", 100);
110+
SensorsAnalytics sa = new SensorsAnalytics(consumer);
111+
Map<String, Object> properties = new HashMap<>();
112+
properties.put("test", "test");
113+
properties.put("$project", "abc");
114+
properties.put("$token", "123");
115+
sa.track("123", true, "test01", properties);
116+
sa.track("123", true, "test01", properties);
117+
}
118+
119+
@Test
120+
public void testInit06() throws InvalidArgumentException {
121+
consumer = new ConcurrentLoggingConsumer("test.log", "lock.log", 100, LogSplitMode.DAY);
122+
SensorsAnalytics sa = new SensorsAnalytics(consumer);
123+
Map<String, Object> properties = new HashMap<>();
124+
properties.put("test", "test");
125+
properties.put("$project", "abc");
126+
properties.put("$token", "123");
127+
sa.track("123", true, "test01", properties);
128+
sa.track("123", true, "test01", properties);
129+
}
130+
131+
@Test
132+
public void testInit07() throws InvalidArgumentException {
133+
consumer = new ConcurrentLoggingConsumer("test.log", "lock.log", 100, LogSplitMode.HOUR);
134+
SensorsAnalytics sa = new SensorsAnalytics(consumer);
135+
Map<String, Object> properties = new HashMap<>();
136+
properties.put("test", "test");
137+
properties.put("$project", "abc");
138+
properties.put("$token", "123");
139+
sa.track("123", true, "test01", properties);
140+
sa.track("123", true, "test01", properties);
141+
}
142+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package com.sensorsdata.analytics.javasdk;
2+
3+
import com.sensorsdata.analytics.javasdk.bean.EventRecord;
4+
import com.sensorsdata.analytics.javasdk.consumer.DebugConsumer;
5+
import com.sensorsdata.analytics.javasdk.exceptions.InvalidArgumentException;
6+
7+
import org.junit.Test;
8+
9+
import java.util.Calendar;
10+
11+
/**
12+
* debugConsumer 单元测试
13+
*
14+
* @author fangzhuo
15+
* @version 1.0.0
16+
* @since 2022/01/18 18:55
17+
*/
18+
public class DebugConsumerTest extends SensorsBaseTest {
19+
20+
@Test
21+
public void checkDataSend() throws InvalidArgumentException {
22+
DebugConsumer consumer = new DebugConsumer("http://localhost:8888/sa", true);
23+
SensorsAnalytics sa = new SensorsAnalytics(consumer);
24+
EventRecord firstRecord = EventRecord.builder().setDistinctId("a123").isLoginId(Boolean.FALSE)
25+
.setEventName("track")
26+
.addProperty("$time", Calendar.getInstance().getTime())
27+
.addProperty("Channel", "baidu")
28+
.addProperty("$project", "abc")
29+
.addProperty("$token", "123")
30+
.build();
31+
sa.track(firstRecord);
32+
}
33+
}

0 commit comments

Comments
 (0)