<commit_before>package com.orientechnologies.orient.server.distributed;

import org.junit.Assert;
import org.junit.Test;

import com.orientechnologies.orient.core.metadata.schema.OClass;
import com.orientechnologies.orient.core.metadata.schema.OType;
import com.orientechnologies.orient.core.record.impl.ODocument;
import com.orientechnologies.orient.core.sql.OCommandSQL;
import com.tinkerpop.blueprints.Direction;
import com.tinkerpop.blueprints.Edge;
import com.tinkerpop.blueprints.Vertex;
import com.tinkerpop.blueprints.impls.orient.*;

public class TestSharding extends AbstractServerClusterTest {

  protected final static int SERVERS     = 3;
  protected OrientVertex[]   vertices;
  protected int[]            versions;
  protected long             totalAmount = 0;

  @Test
  public void test() throws Exception {
    init(SERVERS);
    prepare(false);
    execute();
  }

  @Override
  protected String getDatabaseName() {
    return "sharding";
  }

  @Override
  protected String getDistributedServerConfiguration(final ServerRun server) {
    return "sharded-dserver-config-" + server.getServerId() + ".xml";
  }

  @Override
  protected void onAfterDatabaseCreation(OrientBaseGraph graphNoTx) {
    final OrientVertexType clientType = graphNoTx.createVertexType("Client-Type");
    final OrientVertexType.OrientVertexProperty prop = clientType.createProperty("name-property", OType.STRING);
    prop.createIndex(OClass.INDEX_TYPE.NOTUNIQUE);

    clientType.addCluster("client-type_europe");
    clientType.addCluster("client-type_usa");
    clientType.addCluster("client-type_asia");

    graphNoTx.createVertexType("Product-Type");
    graphNoTx.createVertexType("Hobby-Type");

    graphNoTx.createEdgeType("Knows-Type");
    graphNoTx.createEdgeType("Buy-Type");
    graphNoTx.createEdgeType("Loves-Type");
  }

  @Override
  protected void executeTest() throws Exception {
    try {
      OrientGraphFactory localFactory = new OrientGraphFactory("plocal:target/server0/databases/" + getDatabaseName());
      OrientGraphNoTx graphNoTx = localFactory.getNoTx();

      final OrientVertex product;
      final OrientVertex fishing;

      OrientBaseGraph graph = localFactory.getTx();
      try {
        product = graph.addVertex("class:Product-Type");

        fishing = graph.addVertex("class:Hobby-Type");
        fishing.setProperty("name-property", "Fishing");
      } finally {
        graph.shutdown();
      }

      Assert.assertEquals(product.getRecord().getVersion(), 1);
      Assert.assertEquals(fishing.getRecord().getVersion(), 1);

      versions = new int[serverInstance.size()];
      vertices = new OrientVertex[serverInstance.size()];

      for (int i = 0; i < vertices.length; ++i) {<commit_msg>Fixed distributed tests<commit_after>package com.orientechnologies.orient.server.distributed;

import org.junit.Assert;
import org.junit.Test;

import com.orientechnologies.orient.core.metadata.schema.OClass;
import com.orientechnologies.orient.core.metadata.schema.OType;
import com.orientechnologies.orient.core.record.impl.ODocument;
import com.orientechnologies.orient.core.sql.OCommandSQL;
import com.tinkerpop.blueprints.Direction;
import com.tinkerpop.blueprints.Edge;
import com.tinkerpop.blueprints.Vertex;
import com.tinkerpop.blueprints.impls.orient.*;

public class TestSharding extends AbstractServerClusterTest {

  protected final static int SERVERS     = 3;
  protected OrientVertex[]   vertices;
  protected int[]            versions;
  protected long             totalAmount = 0;

  @Test
  public void test() throws Exception {
    init(SERVERS);
    prepare(false);
    execute();
  }

  @Override
  protected String getDatabaseName() {
    return "sharding";
  }

  @Override
  protected String getDistributedServerConfiguration(final ServerRun server) {
    return "sharded-dserver-config-" + server.getServerId() + ".xml";
  }

  @Override
  protected void onAfterDatabaseCreation(OrientBaseGraph graphNoTx) {
    final OrientVertexType clientType = graphNoTx.createVertexType("Client-Type");
    final OrientVertexType.OrientVertexProperty prop = clientType.createProperty("name-property", OType.STRING);
    prop.createIndex(OClass.INDEX_TYPE.NOTUNIQUE);

    clientType.addCluster("client-type_europe");
    clientType.addCluster("client-type_usa");
    clientType.addCluster("client-type_asia");

    graphNoTx.createVertexType("Product-Type");
    graphNoTx.createVertexType("Hobby-Type");

    graphNoTx.createEdgeType("Knows-Type");
    graphNoTx.createEdgeType("Buy-Type");
    graphNoTx.createEdgeType("Loves-Type");
  }

  @Override
  protected void executeTest() throws Exception {
    try {
      OrientGraphFactory localFactory = new OrientGraphFactory("plocal:target/server0/databases/" + getDatabaseName());

      final OrientVertex product;
      final OrientVertex fishing;

      OrientBaseGraph graph = localFactory.getTx();
      try {
        product = graph.addVertex("class:Product-Type");

        fishing = graph.addVertex("class:Hobby-Type");
        fishing.setProperty("name-property", "Fishing");
      } finally {
        graph.shutdown();
      }

      Assert.assertEquals(product.getRecord().getVersion(), 1);
      Assert.assertEquals(fishing.getRecord().getVersion(), 1);

      versions = new int[serverInstance.size()];
      vertices = new OrientVertex[serverInstance.size()];

      for (int i = 0; i < vertices.length; ++i) {
{'fraction_non_alphanumeric': 0.1133431625506819, 'fraction_numerical': 0.0022115739034279398, 'mean_word_length': 4.168571428571428, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4632024', 'n_tokens_mistral': 1603, 'n_tokens_neox': 1542, 'n_words': 281}