collection = metastore.getCollection("project", "collection");
51 |
52 | assertEquals(ImmutableSet.copyOf(collection), ImmutableSet.of(
53 | new SchemaField("transaction_date", STRING),
54 | new SchemaField("product", STRING),
55 | new SchemaField("price", DOUBLE)));
56 |
57 | Schema avroSchema = AvroUtil.convertAvroSchema(collection);
58 | GenericData.Record record1 = new GenericData.Record(avroSchema);
59 | record1.put("transaction_date", "1/2/09 6:17");
60 | record1.put("product", "Product1");
61 | record1.put("price", 1200.0);
62 |
63 | GenericData.Record record2 = new GenericData.Record(avroSchema);
64 | record2.put("transaction_date", "1/2/09 4:53");
65 | record2.put("product", "Product2");
66 | record2.put("price", 1500.0);
67 |
68 | EventList eventList = new EventList(Event.EventContext.apiKey("apiKey"), "project", ImmutableList.of(
69 | new Event("project", "collection", null, ImmutableList.copyOf(collection), record1),
70 | new Event("project", "collection", null, ImmutableList.copyOf(collection), record2)));
71 | assertEquals(actual, eventList);
72 | }
73 |
74 | }
75 |
--------------------------------------------------------------------------------
/rakam/src/test/java/TestJSCodeCompiler.java:
--------------------------------------------------------------------------------
1 | import okhttp3.OkHttpClient;
2 | import org.rakam.TestingConfigManager;
3 | import org.rakam.util.RAsyncHttpClient;
4 | import org.rakam.util.javascript.JSCodeCompiler;
5 | import org.testng.annotations.Test;
6 |
7 | import javax.script.ScriptException;
8 |
9 | public class TestJSCodeCompiler {
10 | @Test
11 | public void testName()
12 | throws ScriptException {
13 |
14 | JSCodeCompiler jsCodeCompiler = new JSCodeCompiler(new TestingConfigManager(),
15 | new RAsyncHttpClient(new OkHttpClient()),
16 | (project, prefix) -> new JSCodeCompiler.TestLogger(), false, true);
17 | // jsCodeCompiler.createEngine("test", "new Array(100000000).concat(new Array(100000000));", "");
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/rakam/src/test/java/bloom/OoaBFilter.java:
--------------------------------------------------------------------------------
1 | package bloom;
2 |
3 | import com.google.common.hash.HashCode;
4 | import com.google.common.hash.HashFunction;
5 | import com.google.common.hash.Hashing;
6 | import com.google.common.math.IntMath;
7 |
8 | import java.math.RoundingMode;
9 |
10 | /**
11 | * OoaBFilter is used to filter out duplicate elements from a given dataset or stream. It is
12 | * guaranteed to never return a false positive (that is, it will never say that an item has already
13 | * been seen by the filter when it has not) but may return a false negative.
14 | *
15 | * The check is syncronized on the individual buffer. Depending on the dataset, hash function
16 | * and size of the underlying array lock contention should be very low. Dataset/hash function
17 | * combinations that cause many collisions will result in more contention.
18 | *
19 | * OoaBFilter is thread-safe.
20 | */
21 | public class OoaBFilter {
22 | private static final HashFunction HASH_FUNC = Hashing.murmur3_32();
23 | private final long[] leastSignificantBitsArray;
24 | private final long[] mostSignificantBitsArray;
25 | private final int sizeMask;
26 |
27 | public OoaBFilter(int size) {
28 | leastSignificantBitsArray = new long[size];
29 | mostSignificantBitsArray = new long[size];
30 |
31 | this.sizeMask = IntMath.pow(2, IntMath.log2(size, RoundingMode.CEILING)) - 1;
32 | }
33 |
34 | public boolean containsAndAdd(long leastSignificantBits, long mostSignificantBits) {
35 | HashCode code = HASH_FUNC.hashLong(leastSignificantBits);
36 | int index = code.asInt() & sizeMask;
37 |
38 | int buffer = (int) leastSignificantBitsArray[index];
39 | if (mostSignificantBitsArray[buffer] == mostSignificantBits) {
40 | return true;
41 | } else {
42 | mostSignificantBitsArray[buffer] = mostSignificantBits;
43 | return false;
44 | }
45 | }
46 | }
--------------------------------------------------------------------------------
/rakam/src/test/java/bloom/TestFilter.java:
--------------------------------------------------------------------------------
1 | package bloom;
2 |
3 | import java.util.UUID;
4 |
5 | public class TestFilter {
6 |
7 | // @Test
8 | public void testName()
9 | throws Exception {
10 | OoaBFilter byteArrayFilter = new OoaBFilter(1000000);
11 |
12 | while (true) {
13 | UUID uuid = UUID.randomUUID();
14 | long leastSignificantBits = uuid.getLeastSignificantBits();
15 | long mostSignificantBits = uuid.getMostSignificantBits();
16 |
17 | if (byteArrayFilter.containsAndAdd(leastSignificantBits, mostSignificantBits)) {
18 | throw new RuntimeException();
19 | }
20 | }
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/system.properties:
--------------------------------------------------------------------------------
1 | java.runtime.version=1.8
--------------------------------------------------------------------------------