Example #1
0
  @Test
  public void stringSerialization() {
    // Characters
    DataOutput out = serialize.getDataOutput(((int) Character.MAX_VALUE) * 2 + 8, true);
    for (char c = Character.MIN_VALUE; c < Character.MAX_VALUE; c++) {
      out.writeObjectNotNull(Character.valueOf(c));
    }
    ReadBuffer b = out.getStaticBuffer().asReadBuffer();
    for (char c = Character.MIN_VALUE; c < Character.MAX_VALUE; c++) {
      assertEquals(c, serialize.readObjectNotNull(b, Character.class).charValue());
    }

    // String
    for (int t = 0; t < 10000; t++) {
      DataOutput out1 = serialize.getDataOutput(32 + 5, true);
      DataOutput out2 = serialize.getDataOutput(32 + 5, true);
      String s1 = RandomGenerator.randomString(1, 32);
      String s2 = RandomGenerator.randomString(1, 32);
      out1.writeObjectNotNull(s1);
      out2.writeObjectNotNull(s2);
      StaticBuffer b1 = out1.getStaticBuffer();
      StaticBuffer b2 = out2.getStaticBuffer();
      assertEquals(s1, serialize.readObjectNotNull(b1.asReadBuffer(), String.class));
      assertEquals(s2, serialize.readObjectNotNull(b2.asReadBuffer(), String.class));
      assertEquals(
          s1 + " vs " + s2, Integer.signum(s1.compareTo(s2)), Integer.signum(b1.compareTo(b2)));
    }
  }
    @Override
    protected void doLoad() {
      TitanKey weight = makeWeightPropertyKey("weight");
      TitanKey id = makeIntegerUIDPropertyKey("uid");
      TitanLabel knows = makeKeyedEdgeLabel("knows", id, weight);
      TitanKey name = makeUniqueStringPropertyKey("name");

      String[] names = new String[noNodes];
      TitanVertex[] nodes = new TitanVertex[noNodes];
      for (int i = 0; i < noNodes; i++) {
        do {
          names[i] = RandomGenerator.randomString();
          // Retry in case of collision with existing name
        } while (null != tx.getVertex(name, names[i]));
        nodes[i] = tx.addVertex();
        nodes[i].addProperty(name, names[i]);
        nodes[i].addProperty(id, i);
      }
      log.info("Nodes loaded.");
      int offsets[] = {-99, -71, -20, -17, -13, 2, 7, 15, 33, 89};
      assert offsets.length == noEdgesPerNode;

      for (int i = 0; i < noNodes; i++) {
        TitanVertex n = nodes[i];
        for (int e = 0; e < noEdgesPerNode; e++) {
          TitanVertex n2 = nodes[wrapAround(i + offsets[e], noNodes)];
          TitanEdge r = n.addEdge(knows, n2);
          r.addProperty(id, RandomGenerator.randomInt(0, Integer.MAX_VALUE));
          r.addProperty(weight, Math.random());
        }
        if ((i + 1) % 10000 == 0) System.out.println("" + (i + 1));
      }
    }
    @Override
    public void doLoad() {

      TitanLabel connect = makeSimpleEdgeLabel("connect");
      TitanKey name = makeUniqueStringPropertyKey("name");
      TitanKey id = makeIntegerUIDPropertyKey("uid");

      String[] names = new String[noNodes];
      TitanVertex[] nodes = new TitanVertex[noNodes];
      for (int i = 0; i < noNodes; i++) {
        do {
          names[i] = RandomGenerator.randomString();
          // Retry in case of collision with existing name
        } while (null != tx.getVertex(name, names[i]));
        nodes[i] = tx.addVertex();
        nodes[i].addProperty(name, names[i]);
        nodes[i].addProperty(id, i);
      }
      log.info("Nodes loaded.");
      int offsets[] = {-99, -71, -20, -17, -13, 2, 7, 15, 33, 89};
      assert offsets.length == noEdgesPerNode;

      for (int i = 0; i < noNodes; i++) {
        TitanVertex n = nodes[i];
        for (int e = 0; e < noEdgesPerNode; e++) {
          TitanVertex n2 = nodes[wrapAround(i + offsets[e], noNodes)];
          n.addEdge(connect, n2);
        }
        if ((i + 1) % 10000 == 0) System.out.println("" + (i + 1));
      }
    }
 @Test
 public void intervalTest1() {
   String[][] values = generateValues();
   log.debug("Loading values...");
   loadValues(values);
   Set<KeyColumn> deleted = deleteValues(7);
   clopen();
   int trails = 5000;
   for (int t = 0; t < trails; t++) {
     int key = RandomGenerator.randomInt(0, numKeys);
     int start = RandomGenerator.randomInt(0, numColumns);
     int end = RandomGenerator.randomInt(start, numColumns);
     int limit = RandomGenerator.randomInt(1, 30);
     checkSlice(values, deleted, key, start, end, limit);
     checkSlice(values, deleted, key, start, end, -1);
   }
 }