Skip to content

Commit

Permalink
feat: XEI (#40)
Browse files Browse the repository at this point in the history
  • Loading branch information
styluo authored Nov 27, 2023
1 parent 3d79c6b commit ff5f9f1
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 9 deletions.
10 changes: 7 additions & 3 deletions src/main/java/io/growing/sdk/java/dto/GioCdpEventMessage.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ public class GioCdpEventMessage extends GioCDPMessage<EventV3Dto> implements Ser

private static final long serialVersionUID = -2414503426226355459L;

public static final String XEI_USER_KEY = "$notuser";

private final EventV3Dto event;

private GioCdpEventMessage(EventV3Dto.Builder builder) {
Expand Down Expand Up @@ -49,9 +51,11 @@ public boolean isIllegal() {
return true;
}

if (StringUtils.isBlank(event.getUserId()) && StringUtils.isBlank(event.getDeviceId())) {
GioLogger.error("GioCdpEventMessage: userId and anonymousId are empty");
return true;
if (!XEI_USER_KEY.equals(event.getUserKey())) {
if (StringUtils.isBlank(event.getUserId()) && StringUtils.isBlank(event.getDeviceId())) {
GioLogger.error("GioCdpEventMessage: userId and anonymousId are empty");
return true;
}
}

return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public void checkProperties() {

Properties properties = new Properties();

properties.setProperty("api.host", "http://localhost:8080");
properties.setProperty("api.host", "https://www.growingio.com");
properties.setProperty("project.id", "123456654321");
properties.setProperty("msg.store.strategy", "abortPolicy");
properties.setProperty("run.mode", "production");
Expand Down
41 changes: 40 additions & 1 deletion src/test/java/io/growing/sdk/java/test/Case1MockHttpTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public static void before() {
setStaticField(RunMode.class, "currentMode", null);
Properties properties = new Properties();
properties.setProperty("run.mode", "production");
properties.setProperty("api.host", "http://117.50.105.254:8080");
properties.setProperty("api.host", "https://www.growingio.com");
GrowingAPI.initConfig(properties);
sender = new GrowingAPI.Builder().setDataSourceId(DATASOURCE_ID).setProjectKey(PROJECT_KEY).build();
factory = new StubStreamHandlerFactory();
Expand Down Expand Up @@ -68,6 +68,45 @@ public void afterTest() {
}
}

@Test
public void sendXEIEvent() throws InterruptedException {
final CountDownLatch countDownLatch = new CountDownLatch(1);

factory.setStubHttpURLConnectionListener(new StubStreamHandlerFactory.StubHttpURLConnectionListener() {
@Override
public void onSend(URL url, byte[] msg) {
try {
EventV3List eventList = EventV3List.parseFrom(msg);
EventV3Dto customEvent = eventList.getValues(0);
Assert.assertEquals(DATASOURCE_ID, customEvent.getDataSourceId());
Assert.assertEquals(PROJECT_KEY, customEvent.getProjectKey());

Assert.assertEquals("CUSTOM", customEvent.getEventType().name());
Assert.assertEquals("payOrder", customEvent.getEventName());

Assert.assertEquals(GioCdpEventMessage.XEI_USER_KEY, customEvent.getUserKey());
Map<String, String> attributes = customEvent.getAttributesMap();
Assert.assertEquals("0001", attributes.get("prod_id"));
Assert.assertEquals("15.52", attributes.get("money"));

} catch (Exception e) {
mException = e;
}

countDownLatch.countDown();
}
});

sender.send(new GioCdpEventMessage.Builder()
.eventKey("payOrder")
.loginUserKey(GioCdpEventMessage.XEI_USER_KEY)
.addEventVariable("prod_id", "0001")
.addEventVariable("money", "15.52")
.build());

countDownLatch.await();
}

@Test
public void sendCustomEvent() throws InterruptedException {
final CountDownLatch countDownLatch = new CountDownLatch(1);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
package io.growing.sdk.java.test;

import io.growing.sdk.java.dto.GioCdpEventMessage;
import io.growing.sdk.java.dto.GioCdpItemMessage;
import io.growing.sdk.java.dto.GioCdpUserMappingMessage;
import io.growing.sdk.java.dto.GioCdpUserMessage;
import io.growing.sdk.java.dto.*;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
Expand All @@ -26,6 +23,12 @@ public void checkCustomMessage() {
.build();
Assert.assertFalse(eventMessage.isIllegal());

eventMessage = new GioCdpEventMessage.Builder()
.eventKey("event_name")
.loginUserKey(GioCdpEventMessage.XEI_USER_KEY)
.build();
Assert.assertFalse(eventMessage.isIllegal());

eventMessage = new GioCdpEventMessage.Builder()
.eventKey("event_name")
.build();
Expand Down

0 comments on commit ff5f9f1

Please sign in to comment.