|
@@ -0,0 +1,109 @@
|
|
|
|
|
+package com.adx.tencent.conversionsync;
|
|
|
|
|
+
|
|
|
|
|
+import com.adx.tencent.baidu.model.PaymentInfo;
|
|
|
|
|
+import com.adx.tencent.honor.model.HonorBidRecord;
|
|
|
|
|
+import com.adx.tencent.honor.store.HonorColdStore;
|
|
|
|
|
+import com.adx.tencent.honor.store.HonorHotStore;
|
|
|
|
|
+import com.adx.tencent.oppo.model.OppoBidRecord;
|
|
|
|
|
+import com.adx.tencent.oppo.store.OppoColdStore;
|
|
|
|
|
+import com.adx.tencent.oppo.store.OppoHotStore;
|
|
|
|
|
+import com.adx.tencent.storage.RedisHotStore;
|
|
|
|
|
+import com.adx.tencent.storage.TiDBColdStore;
|
|
|
|
|
+import com.adx.tencent.storage.model.BidRecord;
|
|
|
|
|
+import com.adx.tencent.storage.model.ConversionRecord;
|
|
|
|
|
+import com.adx.tencent.vivo.model.VivoBidRecord;
|
|
|
|
|
+import com.adx.tencent.vivo.store.VivoColdStore;
|
|
|
|
|
+import com.adx.tencent.vivo.store.VivoHotStore;
|
|
|
|
|
+import com.fasterxml.jackson.databind.DeserializationFeature;
|
|
|
|
|
+import com.fasterxml.jackson.databind.ObjectMapper;
|
|
|
|
|
+import com.fasterxml.jackson.databind.json.JsonMapper;
|
|
|
|
|
+import org.junit.jupiter.api.Test;
|
|
|
|
|
+import org.springframework.data.redis.core.StringRedisTemplate;
|
|
|
|
|
+import org.springframework.data.redis.core.ValueOperations;
|
|
|
|
|
+
|
|
|
|
|
+import java.time.Duration;
|
|
|
|
|
+import java.util.List;
|
|
|
|
|
+
|
|
|
|
|
+import static org.junit.jupiter.api.Assertions.assertEquals;
|
|
|
|
|
+import static org.junit.jupiter.api.Assertions.assertSame;
|
|
|
|
|
+import static org.mockito.Mockito.mock;
|
|
|
|
|
+import static org.mockito.Mockito.when;
|
|
|
|
|
+
|
|
|
|
|
+class OtherMediaAttributionTest {
|
|
|
|
|
+ private final ObjectMapper mapper = JsonMapper.builder()
|
|
|
|
|
+ .findAndAddModules()
|
|
|
|
|
+ .disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES)
|
|
|
|
|
+ .build();
|
|
|
|
|
+
|
|
|
|
|
+ @Test
|
|
|
|
|
+ void incompleteTencentCacheFallsBackToColdRecord() throws Exception {
|
|
|
|
|
+ StringRedisTemplate redis = mock(StringRedisTemplate.class);
|
|
|
|
|
+ @SuppressWarnings("unchecked") ValueOperations<String, String> values = mock(ValueOperations.class);
|
|
|
|
|
+ TiDBColdStore cold = mock(TiDBColdStore.class);
|
|
|
|
|
+ BidRecord incomplete = new BidRecord(); incomplete.setQk("qk");
|
|
|
|
|
+ BidRecord complete = new BidRecord(); complete.setQk("qk"); complete.setMedia("tencent"); complete.setTagId("tag");
|
|
|
|
|
+ when(redis.opsForValue()).thenReturn(values);
|
|
|
|
|
+ when(values.multiGet(List.of("adx:tencent:bid:qk"))).thenReturn(List.of(mapper.writeValueAsString(incomplete)));
|
|
|
|
|
+ when(cold.getBidsByQks(List.of("qk"))).thenReturn(List.of(complete));
|
|
|
|
|
+
|
|
|
|
|
+ RedisHotStore store = new RedisHotStore(redis, mapper, cold, "adx:tencent:", "events", Duration.ofHours(24), 50_000);
|
|
|
|
|
+ assertSame(complete, store.findBidsByQks(List.of("qk")).get("qk"));
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Test
|
|
|
|
|
+ void incompleteHonorCacheFallsBackToColdRecord() throws Exception {
|
|
|
|
|
+ StringRedisTemplate redis = mock(StringRedisTemplate.class);
|
|
|
|
|
+ @SuppressWarnings("unchecked") ValueOperations<String, String> values = mock(ValueOperations.class);
|
|
|
|
|
+ HonorColdStore cold = mock(HonorColdStore.class);
|
|
|
|
|
+ HonorBidRecord incomplete = new HonorBidRecord(); incomplete.setQk("qk");
|
|
|
|
|
+ HonorBidRecord complete = new HonorBidRecord(); complete.setQk("qk"); complete.setMedia("honor"); complete.setTagId("tag");
|
|
|
|
|
+ when(redis.opsForValue()).thenReturn(values);
|
|
|
|
|
+ when(values.multiGet(List.of("adx:honor:bid:qk"))).thenReturn(List.of(mapper.writeValueAsString(incomplete)));
|
|
|
|
|
+ when(cold.getBidsByQks(List.of("qk"))).thenReturn(List.of(complete));
|
|
|
|
|
+
|
|
|
|
|
+ HonorHotStore store = new HonorHotStore(redis, mapper, cold, "adx:honor:", "events", Duration.ofHours(24), 50_000);
|
|
|
|
|
+ assertSame(complete, store.findBidsByQks(List.of("qk")).get("qk"));
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Test
|
|
|
|
|
+ void incompleteVivoCacheFallsBackToColdRecord() throws Exception {
|
|
|
|
|
+ StringRedisTemplate redis = mock(StringRedisTemplate.class);
|
|
|
|
|
+ @SuppressWarnings("unchecked") ValueOperations<String, String> values = mock(ValueOperations.class);
|
|
|
|
|
+ VivoColdStore cold = mock(VivoColdStore.class);
|
|
|
|
|
+ VivoBidRecord incomplete = new VivoBidRecord(); incomplete.setQk("qk");
|
|
|
|
|
+ VivoBidRecord complete = new VivoBidRecord(); complete.setQk("qk"); complete.setMedia("vivo"); complete.setTagId("tag");
|
|
|
|
|
+ when(redis.opsForValue()).thenReturn(values);
|
|
|
|
|
+ when(values.multiGet(List.of("adx:vivo:bid:qk"))).thenReturn(List.of(mapper.writeValueAsString(incomplete)));
|
|
|
|
|
+ when(cold.getBidsByQks(List.of("qk"))).thenReturn(List.of(complete));
|
|
|
|
|
+
|
|
|
|
|
+ VivoHotStore store = new VivoHotStore(redis, mapper, cold, "adx:vivo:", "events", Duration.ofHours(24), 50_000);
|
|
|
|
|
+ assertSame(complete, store.findBidsByQks(List.of("qk")).get("qk"));
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Test
|
|
|
|
|
+ void incompleteOppoCacheFallsBackToColdRecord() throws Exception {
|
|
|
|
|
+ StringRedisTemplate redis = mock(StringRedisTemplate.class);
|
|
|
|
|
+ @SuppressWarnings("unchecked") ValueOperations<String, String> values = mock(ValueOperations.class);
|
|
|
|
|
+ OppoColdStore cold = mock(OppoColdStore.class);
|
|
|
|
|
+ OppoBidRecord incomplete = new OppoBidRecord(); incomplete.setQk("qk");
|
|
|
|
|
+ OppoBidRecord complete = new OppoBidRecord(); complete.setQk("qk"); complete.setTagId("tag");
|
|
|
|
|
+ when(redis.opsForValue()).thenReturn(values);
|
|
|
|
|
+ when(values.multiGet(List.of("adx:oppo:bid:qk"))).thenReturn(List.of(mapper.writeValueAsString(incomplete)));
|
|
|
|
|
+ when(cold.getBidsByQks(List.of("qk"))).thenReturn(List.of(complete));
|
|
|
|
|
+
|
|
|
|
|
+ OppoHotStore store = new OppoHotStore(redis, mapper, cold, "events", Duration.ofHours(24), 50_000);
|
|
|
|
|
+ assertSame(complete, store.findBidsByQks(List.of("qk")).get("qk"));
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Test
|
|
|
|
|
+ void oppoConversionKeepsMediaAndTagId() {
|
|
|
|
|
+ PaymentInfo payment = new PaymentInfo();
|
|
|
|
|
+ payment.setQk("qk"); payment.setDate("20261016"); payment.setDeviceId("device"); payment.setAct(1);
|
|
|
|
|
+ OppoBidRecord bid = new OppoBidRecord(); bid.setTagId("jlt108");
|
|
|
|
|
+
|
|
|
|
|
+ ConversionRecord record = ConversionSyncService.toOppoConversionRecord(payment, bid);
|
|
|
|
|
+
|
|
|
|
|
+ assertEquals("oppo", record.getMedia());
|
|
|
|
|
+ assertEquals("jlt108", record.getTagId());
|
|
|
|
|
+ }
|
|
|
|
|
+}
|