13
13
// limitations under the License.
14
14
package com .google .android .datatransport .runtime .scheduling .persistence ;
15
15
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 ;
16
21
import static com .google .common .truth .Truth .assertThat ;
17
22
18
- import com .google .android .datatransport .Priority ;
19
23
import com .google .android .datatransport .runtime .EventInternal ;
20
24
import com .google .android .datatransport .runtime .TransportContext ;
21
- import com .google .android .datatransport .runtime .time .Clock ;
22
25
import com .google .android .datatransport .runtime .time .TestClock ;
23
26
import com .google .android .datatransport .runtime .time .UptimeClock ;
24
- import java .util .Arrays ;
25
- import java .util .Collection ;
26
- import org .junit .Before ;
27
27
import org .junit .Test ;
28
28
import org .junit .runner .RunWith ;
29
- import org .robolectric .ParameterizedRobolectricTestRunner ;
29
+ import org .robolectric .RobolectricTestRunner ;
30
30
import org .robolectric .RuntimeEnvironment ;
31
31
32
- @ RunWith (ParameterizedRobolectricTestRunner .class )
32
+ @ RunWith (RobolectricTestRunner .class )
33
33
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 =
40
37
EventInternal .builder ()
41
38
.setTransportName ("42" )
42
39
.setEventMillis (1 )
@@ -45,69 +42,33 @@ public class SchemaManagerTest {
45
42
.addMetadata ("key1" , "value1" )
46
43
.addMetadata ("key2" , "value2" )
47
44
.build ();
45
+ private static final EventInternal EVENT2 =
46
+ EVENT1 .toBuilder ().setPayload ("World" .getBytes ()).build ();
48
47
49
48
private static final long HOUR = 60 * 60 * 1000 ;
50
49
private static final EventStoreConfig CONFIG =
51
50
EventStoreConfig .DEFAULT .toBuilder ().setLoadBatchSize (5 ).setEventCleanUpAge (HOUR ).build ();
52
51
53
52
private final TestClock clock = new TestClock (1 );
54
- private SQLiteEventStore store ;
55
- private final SchemaManager schemaManager ;
56
53
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 );
93
61
94
62
@ 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 );
101
67
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 );
108
70
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 );
112
73
}
113
74
}
0 commit comments