Skip to content

Commit ff28061

Browse files
committed
Fixed tests
1 parent 209766a commit ff28061

File tree

2 files changed

+28
-67
lines changed

2 files changed

+28
-67
lines changed

transport/transport-runtime/src/test/java/com/google/android/datatransport/runtime/scheduling/persistence/SQLiteEventStoreTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ private static SQLiteEventStore newStoreWithConfig(Clock clock, EventStoreConfig
6464
EventStoreModule.CREATE_EVENT_METADATA_SQL_V1,
6565
EventStoreModule.CREATE_CONTEXTS_SQL_V1,
6666
EventStoreModule.CREATE_EVENT_BACKEND_INDEX_V1,
67-
EventStoreModule.CREATE_CONTEXT_BACKEND_PRIORITY_INDEX_V1 )));
67+
EventStoreModule.CREATE_CONTEXT_BACKEND_PRIORITY_INDEX_V1)));
6868
}
6969

7070
@Test

transport/transport-runtime/src/test/java/com/google/android/datatransport/runtime/scheduling/persistence/SchemaManagerTest.java

Lines changed: 27 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -13,30 +13,27 @@
1313
// limitations under the License.
1414
package com.google.android.datatransport.runtime.scheduling.persistence;
1515

16+
import static com.google.android.datatransport.runtime.scheduling.persistence.EventStoreModule.CREATE_CONTEXTS_SQL_V1;
17+
import static com.google.android.datatransport.runtime.scheduling.persistence.EventStoreModule.CREATE_CONTEXT_BACKEND_PRIORITY_INDEX_V1;
18+
import static com.google.android.datatransport.runtime.scheduling.persistence.EventStoreModule.CREATE_EVENTS_SQL_V1;
19+
import static com.google.android.datatransport.runtime.scheduling.persistence.EventStoreModule.CREATE_EVENT_BACKEND_INDEX_V1;
20+
import static com.google.android.datatransport.runtime.scheduling.persistence.EventStoreModule.CREATE_EVENT_METADATA_SQL_V1;
1621
import static com.google.common.truth.Truth.assertThat;
1722

18-
import com.google.android.datatransport.Priority;
1923
import com.google.android.datatransport.runtime.EventInternal;
2024
import com.google.android.datatransport.runtime.TransportContext;
21-
import com.google.android.datatransport.runtime.time.Clock;
2225
import com.google.android.datatransport.runtime.time.TestClock;
2326
import com.google.android.datatransport.runtime.time.UptimeClock;
24-
import java.util.Arrays;
25-
import java.util.Collection;
26-
import org.junit.Before;
2727
import org.junit.Test;
2828
import org.junit.runner.RunWith;
29-
import org.robolectric.ParameterizedRobolectricTestRunner;
29+
import org.robolectric.RobolectricTestRunner;
3030
import org.robolectric.RuntimeEnvironment;
3131

32-
@RunWith(ParameterizedRobolectricTestRunner.class)
32+
@RunWith(RobolectricTestRunner.class)
3333
public class SchemaManagerTest {
34-
35-
private static final TransportContext TRANSPORT_CONTEXT =
36-
TransportContext.builder().setBackendName("backend1").build();
37-
private static final TransportContext ANOTHER_TRANSPORT_CONTEXT =
38-
TransportContext.builder().setBackendName("backend2").build();
39-
private static final EventInternal EVENT =
34+
private static final TransportContext CONTEXT1 =
35+
TransportContext.builder().setBackendName("b1").build();
36+
private static final EventInternal EVENT1 =
4037
EventInternal.builder()
4138
.setTransportName("42")
4239
.setEventMillis(1)
@@ -45,69 +42,33 @@ public class SchemaManagerTest {
4542
.addMetadata("key1", "value1")
4643
.addMetadata("key2", "value2")
4744
.build();
45+
private static final EventInternal EVENT2 =
46+
EVENT1.toBuilder().setPayload("World".getBytes()).build();
4847

4948
private static final long HOUR = 60 * 60 * 1000;
5049
private static final EventStoreConfig CONFIG =
5150
EventStoreConfig.DEFAULT.toBuilder().setLoadBatchSize(5).setEventCleanUpAge(HOUR).build();
5251

5352
private final TestClock clock = new TestClock(1);
54-
private SQLiteEventStore store;
55-
private final SchemaManager schemaManager;
5653

57-
public SchemaManagerTest(
58-
String createEventsSql,
59-
String createEventMetadataSql,
60-
String createContextsSql,
61-
String createEventBackendIndex,
62-
String createContextBackendPriorityIndex) {
63-
schemaManager =
64-
new SchemaManager(
65-
RuntimeEnvironment.application,
66-
new DatabaseBootstrapClient(
67-
createEventsSql,
68-
createEventMetadataSql,
69-
createContextsSql,
70-
createEventBackendIndex,
71-
createContextBackendPriorityIndex));
72-
}
73-
74-
@Before
75-
public void initialize() {
76-
store = newStoreWithConfig(clock, CONFIG, schemaManager);
77-
}
78-
79-
@ParameterizedRobolectricTestRunner.Parameters
80-
public static Collection primeNumbers() {
81-
return Arrays.asList(
82-
new Object[][] {
83-
{
84-
EventStoreModule.CREATE_EVENTS_SQL_V1,
85-
EventStoreModule.CREATE_EVENT_METADATA_SQL_V1,
86-
EventStoreModule.CREATE_CONTEXTS_SQL_V1,
87-
EventStoreModule.CREATE_CONTEXTS_SQL_V1,
88-
EventStoreModule.CREATE_EVENT_BACKEND_INDEX_V1,
89-
EventStoreModule.CREATE_CONTEXTS_SQL_V1
90-
}
91-
});
92-
}
54+
private final DatabaseBootstrapClient V1_BOOTSTRAP_CLIENT =
55+
new DatabaseBootstrapClient(
56+
CREATE_EVENTS_SQL_V1,
57+
CREATE_EVENT_METADATA_SQL_V1,
58+
CREATE_CONTEXTS_SQL_V1,
59+
CREATE_EVENT_BACKEND_INDEX_V1,
60+
CREATE_CONTEXT_BACKEND_PRIORITY_INDEX_V1);
9361

9462
@Test
95-
public void persist_withEventsOfDifferentPriority_shouldEndBeStoredUnderDifferentContexts() {
96-
TransportContext ctx1 = TRANSPORT_CONTEXT;
97-
TransportContext ctx2 = TRANSPORT_CONTEXT.withPriority(Priority.VERY_LOW);
98-
99-
EventInternal event1 = EVENT;
100-
EventInternal event2 = EVENT.toBuilder().setPayload("World".getBytes()).build();
63+
public void persist_correctlyRoundTrips() {
64+
SchemaManager schemaManager =
65+
new SchemaManager(RuntimeEnvironment.application, V1_BOOTSTRAP_CLIENT);
66+
SQLiteEventStore store = new SQLiteEventStore(clock, new UptimeClock(), CONFIG, schemaManager);
10167

102-
PersistedEvent newEvent1 = store.persist(ctx1, event1);
103-
PersistedEvent newEvent2 = store.persist(ctx2, event2);
104-
105-
assertThat(store.loadBatch(ctx1)).containsExactly(newEvent1);
106-
assertThat(store.loadBatch(ctx2)).containsExactly(newEvent2);
107-
}
68+
PersistedEvent newEvent = store.persist(CONTEXT1, EVENT1);
69+
Iterable<PersistedEvent> events = store.loadBatch(CONTEXT1);
10870

109-
private SQLiteEventStore newStoreWithConfig(
110-
Clock clock, EventStoreConfig config, SchemaManager schemaManager) {
111-
return new SQLiteEventStore(clock, new UptimeClock(), config, schemaManager);
71+
assertThat(newEvent.getEvent()).isEqualTo(EVENT1);
72+
assertThat(events).containsExactly(newEvent);
11273
}
11374
}

0 commit comments

Comments
 (0)