Skip to content
Snippets Groups Projects
Commit d6debd1b authored by Rob Adams's avatar Rob Adams
Browse files

Make unit test more reliable on slow machine

parent bc54d863
No related branches found
No related tags found
No related merge requests found
/*
* Copyright 2008-2009 LinkedIn, Inc
* Copyright (c) 2013 Big Switch Networks, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
......@@ -47,7 +48,7 @@ public class TUtils {
/**
* Get a vector clock with events on the sequence of nodes given So
* getClock(1,1,2,2,2) means a clock that has two writes on node 1 and 3
* writes on node 2.
* writes on node 2. The timestamp will be the current time
*
* @param nodes The sequence of nodes
* @return A VectorClock initialized with the given sequence of events
......@@ -56,6 +57,19 @@ public class TUtils {
VectorClock clock = new VectorClock();
return increment(clock, nodes);
}
/**
* Get a vector clock with a the given timestamp and events on the
* sequence of nodes given So getClock(1,1,2,2,2) means a clock that has
* two writes on node 1 and 3 writes on node 2.
*
* @param nodes The sequence of nodes
* @return A VectorClock initialized with the given sequence of events
*/
public static VectorClock getClock(long timestamp, int... nodes) {
VectorClock clock = new VectorClock(timestamp);
return increment(clock, nodes);
}
/**
* Record events for the given sequence of nodes
......
......@@ -36,8 +36,9 @@ import com.google.common.collect.Lists;
public class VectorClockTest {
@Test
public void testEqualsAndHashcode() {
VectorClock one = getClock(1, 2);
VectorClock other = getClock(1, 2);
long now = 5555555555L;
VectorClock one = getClock(now, 1, 2);
VectorClock other = getClock(now, 1, 2);
assertEquals(one, other);
assertEquals(one.hashCode(), other.hashCode());
}
......@@ -62,20 +63,21 @@ public class VectorClockTest {
public void testMerge() {
// merging two clocks should create a clock contain the element-wise
// maximums
assertEquals("Two empty clocks merge to an empty clock.",
getClock().merge(getClock()),
getClock());
getClock().merge(getClock()).getEntries(),
getClock().getEntries());
assertEquals("Merge of a clock with itself does nothing",
getClock(1).merge(getClock(1)),
getClock(1));
assertEquals(getClock(1).merge(getClock(2)), getClock(1, 2));
assertEquals(getClock(1).merge(getClock(1, 2)), getClock(1, 2));
assertEquals(getClock(1, 2).merge(getClock(1)), getClock(1, 2));
getClock(1).merge(getClock(1)).getEntries(),
getClock(1).getEntries());
assertEquals(getClock(1).merge(getClock(2)).getEntries(), getClock(1, 2).getEntries());
assertEquals(getClock(1).merge(getClock(1, 2)).getEntries(), getClock(1, 2).getEntries());
assertEquals(getClock(1, 2).merge(getClock(1)).getEntries(), getClock(1, 2).getEntries());
assertEquals("Two-way merge fails.",
getClock(1, 1, 1, 2, 3, 5).merge(getClock(1, 2, 2, 4)),
getClock(1, 1, 1, 2, 2, 3, 4, 5));
assertEquals(getClock(2, 3, 5).merge(getClock(1, 2, 2, 4, 7)),
getClock(1, 2, 2, 3, 4, 5, 7));
getClock(1, 1, 1, 2, 3, 5).merge(getClock(1, 2, 2, 4)).getEntries(),
getClock(1, 1, 1, 2, 2, 3, 4, 5).getEntries());
assertEquals(getClock(2, 3, 5).merge(getClock(1, 2, 2, 4, 7)).getEntries(),
getClock(1, 2, 2, 3, 4, 5, 7).getEntries());
}
/**
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment