Package sherpa.server

Examples of sherpa.server.DummySherpaServer


public class TestQueryProtocolIterator {

  private static final Logger logger = LoggerFactory.getLogger(TestQueryProtocolIterator.class);
 
  public void helpTestProtocolIterator(int resultRows) throws Exception {
    DummySherpaServer server = new DummySherpaServer(resultRows);
    InetSocketAddress serverAddress = server.getAddress();
   
    try {
      Transceiver tr = new SaslSocketTransceiver(serverAddress);
      SpecificRequestor requestor = new SpecificRequestor(SherpaServer.class, tr);
      SherpaServer queryApi = SpecificRequestor.getClient(SherpaServer.class, requestor);
      QueryExecution protocol = new QueryExecution(queryApi);

      protocol.query("fake command",null,null);     
     
      int counter = 0;
      for(List<Object> row : protocol) {
        Assert.assertNotNull(row);
        counter++;
      }
           
      logger.info("Read {} rows", counter);
      Assert.assertEquals(resultRows, counter);
     
    } finally {
      server.shutdown();
    }
  }
View Full Code Here


  @Test
  public void testRepeatOnTransceiver() throws Throwable {
    int resultRows = 15;
 
    DummySherpaServer server = new DummySherpaServer(resultRows);
    InetSocketAddress serverAddress = server.getAddress();
   
    try {
      Transceiver tr = new SaslSocketTransceiver(serverAddress);
      SpecificRequestor requestor = new SpecificRequestor(SherpaServer.class, tr);
      SherpaServer queryApi = SpecificRequestor.getClient(SherpaServer.class, requestor);

      for(int i=0; i<3; i++) {
        //logger.debug("running command {}", i);
       
        QueryExecution protocol = new QueryExecution(queryApi);
        protocol.query("fake command",null,null);     

        int counter = 0;
        for(List<Object> row : protocol) {
          Assert.assertNotNull(row);
          counter++;
        }
             
        //logger.debug("Read {} rows", counter);
        Assert.assertEquals(resultRows, counter);

      }
    } catch (Throwable t) {
      t.printStackTrace();
      throw t;
    } finally {
      server.shutdown();
    }   
  }
View Full Code Here

    ((SHPCommand) command).setBatchSize(batchSize);
    return command.executeQuery();
  }
 
  public void helpTestQueryCursor(int resultRows, int batchSize) {
    DummySherpaServer server = new DummySherpaServer(resultRows);

    try {
      Solutions solutions = helpExecuteQuery(server, batchSize);

      TestCursor.assertCursor(solutions, BEFORE_FIRST);
     
      int counter = 0;
      while (solutions.next()) {
        Map<String,RDFNode> solution = solutions.getResult();
        Assert.assertNotNull(solution);
        Assert.assertEquals(++counter, solutions.getRow());
        int state = ((counter == 1) ? FIRST : NONE) | ((counter == resultRows) ? LAST : NONE);
        TestCursor.assertCursor(solutions, state);
      }

      TestCursor.assertCursor(solutions, AFTER_LAST);
     
      logger.info("Read {} rows", counter);
      Assert.assertEquals(resultRows, counter);

    } finally {
      server.shutdown();
    }
  }
View Full Code Here

      Assert.assertFalse(data.get(i).equals(data.get(i + 1)));
    }
  }

  public void helpTestIteratorNormal(int rows, int batchSize) {
    DummySherpaServer server = new DummySherpaServer(rows);
    try {
      Solutions solutions = helpExecuteQuery(server, batchSize);
      Iterator<Map<String,RDFNode>> iter = solutions.iterator();
      Assert.assertNotNull(iter);
      List<Map<String,RDFNode>> data = new ArrayList<Map<String,RDFNode>>(rows);
      // Traverse the iterator in a normal fashion.
      while (iter.hasNext()) {
        data.add(iter.next());
      }
      helpCheckRows(data, rows);
    } finally {
      server.shutdown();
    }
  }
View Full Code Here

      server.shutdown();
    }
  }
 
  public void helpTestIteratorParanoid(int rows, int batchSize) {
    DummySherpaServer server = new DummySherpaServer(rows);
    try {
      Solutions solutions = helpExecuteQuery(server, batchSize);
      Iterator<Map<String,RDFNode>> iter = solutions.iterator();
      Assert.assertNotNull(iter);
      List<Map<String,RDFNode>> data = new ArrayList<Map<String,RDFNode>>(rows);
      // Traverse the iterator, with lots of extra checks to hasNext();
      Assert.assertEquals(rows > 0, iter.hasNext());
      Assert.assertEquals(rows > 0, iter.hasNext());
      while (iter.hasNext()) {
        data.add(iter.next());
        Assert.assertEquals(data.size() < rows, iter.hasNext());
      }
      helpCheckRows(data, rows);
    } finally {
      server.shutdown();
    }
  }
View Full Code Here

      server.shutdown();
    }
  }
 
  public void helpTestIteratorCount(int rows, int batchSize) {
    DummySherpaServer server = new DummySherpaServer(rows);
    try {
      Solutions solutions = helpExecuteQuery(server, batchSize);
      Iterator<Map<String,RDFNode>> iter = solutions.iterator();
      Assert.assertNotNull(iter);
      List<Map<String,RDFNode>> data = new ArrayList<Map<String,RDFNode>>(rows);
      // Traverse the iterator without calling hasNext()
      for (int i = 0; i < rows; i++) {
        data.add(iter.next());
      }
      Assert.assertFalse(iter.hasNext());
      helpCheckRows(data, rows);
    } finally {
      server.shutdown();
    }
  }
View Full Code Here

  @SuppressWarnings("unchecked")
  @Test
  public void testTimeoutPassedDown() {
    final List<Object> results = new ArrayList<Object>();   
    DummySherpaServer server = new DummySherpaServer(
        new DummyQueryResponder(10) {
          public QueryResponse query(QueryRequest query)
              throws AvroRemoteException {
            results.add(query.properties);
            return super.query(query);
          }
        });
    InetSocketAddress serverAddress = server.getAddress();
   
    try {
      DataSource ds = new SHPDataSource(serverAddress.getHostName(), serverAddress.getPort());
      Connection conn = ds.getConnection(NoCredentials.INSTANCE);
      Command command = conn.createCommand("SELECT ?x ?y WHERE { this should be a real query but the test doesn't actually do anything real. }");
      command.setTimeout(1234);
      command.executeQuery();
     
      // Kind of tricky here - the keys and values are now Avro Utf8 instances which don't compare equal to Strings
      Map<CharSequence,CharSequence> serverProps = (Map<CharSequence,CharSequence>)results.get(0);
      Assert.assertEquals(new Utf8("1234"), serverProps.get(new Utf8(QueryExecution.TIMEOUT)));
     
    } finally {
      server.shutdown();
    }

  }
View Full Code Here

        new Object[][] {
            new Object[] { iri(uri1), iri(uri2), toInt(lit1) },
            new Object[] { iri(uri2), iri(uri1), toInt(lit2) }
        });
   
    DummySherpaServer server = new DummySherpaServer(data);
    try {
      Solutions s = helpExecuteQuery(server, 5);
     
      Assert.assertTrue(s.next());
      Map<String, RDFNode> solution = s.getResult();
      Assert.assertEquals(3, solution.size());
      Assert.assertEquals(uri1, solution.get("a"));
      Assert.assertEquals(uri2, solution.get("b"));
      Assert.assertEquals(lit1, solution.get("c"));
     
      Assert.assertTrue(s.next());
      Assert.assertEquals(uri2, s.getBinding("a"));
      Assert.assertEquals(uri2, s.getNamedNode("a"));
      Assert.assertEquals(uri1, s.getBinding("b"));
      Assert.assertEquals(uri1.getURI(), s.getURI("b"));
      Assert.assertEquals(lit2, s.getBinding("c"));     
      Assert.assertEquals(lit2, s.getLiteral("c"));     
      Assert.assertEquals(20, s.getInt("c"));
     
      Assert.assertFalse(s.next());
    } finally {
      server.shutdown();
    }
  }
View Full Code Here

            new Object[] { aString.getLexical() },
            new Object[] { bNode(bn) },
            new Object[] { null },
        });
   
    DummySherpaServer server = new DummySherpaServer(data);
    try {
      Solutions s = helpExecuteQuery(server, 10);
      String var = "a";
     
      Assert.assertTrue(s.next());
      Assert.assertEquals(uri, s.getBinding(var));
      Assert.assertEquals(uri.getURI(), s.getURI(var));
     
      Assert.assertTrue(s.next());
      Assert.assertEquals(lit1, s.getBinding(var));
      Assert.assertEquals(lit1, s.getLiteral(var));
     
      Assert.assertTrue(s.next());
      Assert.assertEquals(lit2, s.getBinding(var));
      Assert.assertEquals(lit2, s.getLiteral(var));
     
      Assert.assertTrue(s.next());
      Assert.assertEquals(lit3, s.getBinding(var));
      Assert.assertEquals(lit3, s.getLiteral(var));
      Assert.assertEquals(d, s.getDateTime(var));
     
      Assert.assertTrue(s.next());
      Assert.assertEquals(aInt, s.getBinding(var));
      Assert.assertEquals(aInt, s.getLiteral(var));
      Assert.assertEquals(20, s.getInt(var));
     
      Assert.assertTrue(s.next());
      Assert.assertEquals(aLong, s.getBinding(var));
      Assert.assertEquals(aLong, s.getLiteral(var));
     
      Assert.assertTrue(s.next());
      Assert.assertEquals(aBool, s.getBinding(var));
      Assert.assertEquals(aBool, s.getLiteral(var));
      Assert.assertEquals(true, s.getBoolean(var));
     
      Assert.assertTrue(s.next());
      Assert.assertEquals(aFloat, s.getBinding(var));
      Assert.assertEquals(aFloat, s.getLiteral(var));
      Assert.assertTrue(Float.valueOf(aFloat.getLexical()).equals(s.getFloat(var)));
     
      Assert.assertTrue(s.next());
      Assert.assertEquals(aDouble, s.getBinding(var));
      Assert.assertEquals(aDouble, s.getLiteral(var));
      Assert.assertTrue(Double.valueOf(aDouble.getLexical()).equals(s.getDouble(var)));
     
      Assert.assertTrue(s.next());
      Assert.assertEquals(aString, s.getBinding(var));
      Assert.assertEquals(aString, s.getLiteral(var));
      Assert.assertEquals("abcd", s.getString(var));
     
      Assert.assertTrue(s.next());
      Assert.assertEquals(bn, s.getBinding(var));
      Assert.assertEquals(bn, s.getBlankNode(var));
     
      Assert.assertTrue(s.next());
      Assert.assertNull(s.getBinding(var));
      Assert.assertFalse(s.isBound(var));
      Assert.assertNull(s.getNamedNode(var));
      Assert.assertNull(s.getLiteral(var));
      Assert.assertNull(s.getBlankNode(var));
     
      Assert.assertFalse(s.next());
    } finally {
      server.shutdown();
    }
  }
View Full Code Here

TOP

Related Classes of sherpa.server.DummySherpaServer

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.