Exemplo n.º 1
0
  /** goal get shard range 10,14, 15,19, 20,22 */
  @Test
  public void testGetRange7() {
    int offset = 10;
    int limit = 5;
    Long finish = 21l;
    long total = 23;
    Sharding d = new Sharding();
    d.setLimit(offset, limit, finish);
    d.setCounts(total);
    int shards = d.getShards();
    assertEquals(3, shards);

    long[] l3 = {9l, 13l};
    long[] r3 = d.getRange(0);
    assertEquals(l3[0], r3[0]);
    assertEquals(l3[1], r3[1]);

    long[] l4 = {14l, 18l};
    long[] r4 = d.getRange(1);
    assertEquals(l4[0], r4[0]);
    assertEquals(l4[1], r4[1]);

    long[] l5 = {19, 20l};
    long[] r5 = d.getRange(2);
    assertEquals(l5[0], r5[0]);
    assertEquals(l5[1], r5[1]);
  }
Exemplo n.º 2
0
  /** goal get shard range 10,14, 15,19, 20,22 */
  @Test
  public void testGetRange3() {
    int offset = 11;
    int limit = 5;
    Long finish = null;
    long total = 23;
    Sharding d = new Sharding();
    d.setLimit(offset, limit, finish);
    d.setCounts(total);
    int shards = d.getShards();

    assertEquals(3, shards);

    long[] l3 = {10l, 14l};
    long[] r3 = d.getRange(0);
    assertEquals(l3[0], r3[0]);
    assertEquals(l3[1], r3[1]);

    long[] l4 = {15l, 19l};
    long[] r4 = d.getRange(1);
    assertEquals(l4[0], r4[0]);
    assertEquals(l4[1], r4[1]);

    long[] l5 = {20l, 22l};
    long[] r5 = d.getRange(2);
    assertEquals(l5[0], r5[0]);
    assertEquals(l5[1], r5[1]);
  }
Exemplo n.º 3
0
 /** goal query 0-55 (no finish) */
 @Test
 public void testGetEnd4() {
   int offset = 0;
   int limit = 10;
   Long finish = null;
   long total = 55;
   Sharding d = new Sharding();
   d.setLimit(offset, limit, finish);
   d.setCounts(total);
   long end = d.getEnd();
   assertEquals(55, end);
 }
Exemplo n.º 4
0
 /** goal 0-100 (impose finish at 100) */
 @Test
 public void testGetEnd() {
   int offset = 0;
   int limit = 5;
   Long finish = 100l;
   long total = 213;
   Sharding d = new Sharding();
   d.setLimit(offset, limit, finish);
   d.setCounts(total);
   long end = d.getEnd();
   assertEquals(finish.longValue(), end);
 }
Exemplo n.º 5
0
 @Test
 public void testSetLimit() {
   int offset = 0;
   int limit = 5;
   Long finish = 100l;
   long total = 213;
   Sharding d = new Sharding();
   d.setLimit(offset, limit, finish);
   d.setCounts(total);
   assertEquals(offset, d.getOffset());
   assertEquals(limit, d.getLimit());
   assertEquals(finish, d.getFinish());
   assertEquals(total, d.getTotal());
 }
Exemplo n.º 6
0
 /** goal 0-23 (no finish), means that should be 23 shards */
 @Test
 public void testGetPages3() {
   int offset = 0;
   int limit = 5;
   Long finish = null;
   long total = 23;
   Sharding d = new Sharding();
   d.setLimit(offset, limit, finish);
   d.setCounts(total);
   long end = d.getEnd();
   int shards = d.getShards();
   assertEquals(total, end);
   assertEquals(5, shards); // 23.6 is 5 shards
 }
Exemplo n.º 7
0
 /** goal get shard range 2,3 */
 @Test
 public void testGetRange6() {
   int offset = 3;
   int limit = 5;
   Long finish = null;
   long total = 4;
   Sharding d = new Sharding();
   d.setLimit(offset, limit, finish);
   d.setCounts(total);
   int shards = d.getShards();
   assertEquals(1, shards);
   long[] l3 = {2l, 3l};
   long[] r3 = d.getRange(0);
   assertEquals(l3[0], r3[0]);
   assertEquals(l3[1], r3[1]);
 }