package com.orientechnologies.orient.server.distributed;

import com.orientechnologies.orient.core.db.ODatabaseSession;
import com.orientechnologies.orient.core.db.ODatabaseType;
import com.orientechnologies.orient.core.db.OrientDB;
import com.orientechnologies.orient.core.db.OrientDBConfig;
import com.orientechnologies.orient.core.record.OVertex;
import com.orientechnologies.orient.core.sql.executor.OResultSet;
import com.orientechnologies.orient.server.OServer;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;

import javax.management.InstanceAlreadyExistsException;
import javax.management.MBeanRegistrationException;
import javax.management.MalformedObjectNameException;
import javax.management.NotCompliantMBeanException;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;

public class SimpleQueryDistributedTests {

  private OServer          server0;
  private OServer          server1;
  private OServer          server2;
  private OrientDB         remote;
  private ODatabaseSession session;

  @Before
  public void before() throws Exception {
    server0 = OServer.startFromClasspathConfig("orientdb-simple-dserver-config-0.xml");
    server1 = OServer.startFromClasspathConfig("orientdb-simple-dserver-config-1.xml");
    server2 = OServer.startFromClasspathConfig("orientdb-simple-dserver-config-2.xml");
    remote = new OrientDB("remote:localhost", "root", "test", OrientDBConfig.defaultConfig());
    remote.create("test", ODatabaseType.PLOCAL);
    session = remote.open("test", "admin", "admin");
  }

  @Test
  public void test() {
    OVertex vertex = session.newVertex("V");
    vertex.setProperty("name", "one");
    session.save(vertex);
    OResultSet res = session.query("select from V");
    assertTrue(res.hasNext());
    assertEquals(res.next().getProperty("name"), "one");
  }

  @After
  public void after() {
    remote.drop("test");
    remote.close();

    server0.shutdown();
    server1.shutdown();
    server2.shutdown();
  }

}
@@ -51,16 +51,86 @@
 buted;%0A%0A
+import com.orientechnologies.orient.core.config.OGlobalConfiguration;%0A
 import c
@@ -179,24 +179,24 @@
 aseSession;%0A
-
 import com.o
@@ -413,16 +413,79 @@
 Vertex;%0A
+import com.orientechnologies.orient.core.sql.executor.OResult;%0A
 import c
@@ -671,303 +671,8 @@
 t;%0A%0A
-import javax.management.InstanceAlreadyExistsException;%0Aimport javax.management.MBeanRegistrationException;%0Aimport javax.management.MalformedObjectNameException;%0Aimport javax.management.NotCompliantMBeanException;%0Aimport java.io.IOException;%0Aimport java.lang.reflect.InvocationTargetException;%0A%0A
 impo
@@ -1719,24 +1719,24 @@
 hasNext());%0A
-
     assertEq
@@ -1785,16 +1785,640 @@
 );%0A  %7D%0A%0A
+  @Test%0A  public void testRecords() %7B%0A    int records = (OGlobalConfiguration.QUERY_REMOTE_RESULTSET_PAGE_SIZE.getValueAsInteger() + 10);%0A    for (int i = 0; i %3C records; i++) %7B%0A      OVertex vertex = session.newVertex(%22V%22);%0A      vertex.setProperty(%22name%22, %22one%22);%0A      vertex.setProperty(%22pos%22, i);%0A      session.save(vertex);%0A    %7D%0A%0A    OResultSet res = session.query(%22select from V order by pos%22);%0A    for (int i = 0; i %3C records; i++) %7B%0A      assertTrue(res.hasNext());%0A      OResult ele = res.next();%0A      assertEquals((int) ele.getProperty(%22pos%22), i);%0A      assertEquals(ele.getProperty(%22name%22), %22one%22);%0A    %7D%0A  %7D%0A%0A
   @After

add distributed test case on multiple record query