@@ -214,4 +214,76 @@ public void testHistoryOverwrite() {
214214 assertTrue (Uuid .equals (bundle .message ().id (), new Uuid (7 )));
215215 }
216216 }
217+
218+ @ Test
219+ public void testReadWithMissingRoot () {
220+
221+ final Server relay = new Server (8 , 8 );
222+
223+ final Uuid team = new Uuid (3 );
224+ final byte [] secret = { 0x00 , 0x01 , 0x02 };
225+
226+ assertTrue (relay .addTeam (team , secret ));
227+
228+ assertTrue (relay .write (team ,
229+ secret ,
230+ relay .pack (new Uuid (4 ), "User" , Time .now ()),
231+ relay .pack (new Uuid (5 ), "Conversation" , Time .now ()),
232+ relay .pack (new Uuid (6 ), "Hello World" , Time .now ())));
233+
234+ final Collection <Relay .Bundle > read = relay .read (team , secret , new Uuid (7 ), 1 );
235+ assertTrue (read .size () == 1 );
236+
237+ // By the assertion above this loop should only execute once as there should only
238+ // be a single value in the collection.
239+
240+ for (final Relay .Bundle bundle : read ) {
241+ assertTrue (Uuid .equals (bundle .team (), team ));
242+ assertTrue (Uuid .equals (bundle .user ().id (), new Uuid (4 )));
243+ assertTrue (Uuid .equals (bundle .conversation ().id (), new Uuid (5 )));
244+ assertTrue (Uuid .equals (bundle .message ().id (), new Uuid (6 )));
245+ }
246+ }
247+
248+ @ Test
249+ public void testReadMidHistory () {
250+
251+ final Server relay = new Server (8 , 8 );
252+
253+ final Uuid team = new Uuid (3 );
254+ final byte [] secret = { 0x00 , 0x01 , 0x02 };
255+
256+ assertTrue (relay .addTeam (team , secret ));
257+
258+ assertTrue (relay .write (team ,
259+ secret ,
260+ relay .pack (new Uuid (4 ), "User" , Time .now ()),
261+ relay .pack (new Uuid (5 ), "Conversation" , Time .now ()),
262+ relay .pack (new Uuid (6 ), "Hello World" , Time .now ())));
263+
264+ assertTrue (relay .write (team ,
265+ secret ,
266+ relay .pack (new Uuid (7 ), "User" , Time .now ()),
267+ relay .pack (new Uuid (8 ), "Conversation" , Time .now ()),
268+ relay .pack (new Uuid (9 ), "Hello World" , Time .now ())));
269+
270+ assertTrue (relay .write (team ,
271+ secret ,
272+ relay .pack (new Uuid (10 ), "User" , Time .now ()),
273+ relay .pack (new Uuid (11 ), "Conversation" , Time .now ()),
274+ relay .pack (new Uuid (12 ), "Hello World" , Time .now ())));
275+
276+ final Collection <Relay .Bundle > read = relay .read (team , secret , new Uuid (2 ), 1 );
277+ assertTrue (read .size () == 1 );
278+
279+ // By the assertion above this loop should only execute once as there should only
280+ // be a single value in the collection.
281+
282+ for (final Relay .Bundle bundle : read ) {
283+
284+ // The relay server uses a linear id generator starting at 1 - so starting
285+ // bundle 2, the id should be 3.
286+ assertTrue (Uuid .equals (bundle .id (), new Uuid (3 )));
287+ }
288+ }
217289}
0 commit comments