Package com.splout.db.qnode.beans

Examples of com.splout.db.qnode.beans.QueryStatus


      ReplicationEntry repEntry = new ReplicationEntry(0, dnode1.getAddress(), dnode2.getAddress());
      Tablespace tablespace1 = new Tablespace(PartitionMap.oneShardOpenedMap(), new ReplicationMap(Arrays.asList(repEntry)), 1l, 0l);
      handler.getContext().getTablespaceVersionsMap().put(new TablespaceVersion("tablespace1", 1l), tablespace1);
      handler.getContext().getCurrentVersionsMap().put("tablespace1", 1l);

      QueryStatus qStatus = handler.query("tablespace1", "2", "SELECT 1;", null);
      Assert.assertEquals(new Integer(0), qStatus.getShard());
      Assert.assertEquals("[1]", qStatus.getResult().toString());
    } finally {
      handler.close();
      dnode1.stop();
      dnode2.stop();
      Hazelcast.shutdownAll();
View Full Code Here


    Thread.sleep(2000); // TODO How to improve this.

    // Perform N queries, one to each DNode and validate the resultant data
    for(int i = 0; i < N_DNODES; i++) {
      client = getRandomQNodeClient(random, config);
      QueryStatus qStatus = client.query("p1", ((i * 10) + 1) + "", "SELECT * FROM foo;", null);
      assertEquals((Integer) i, qStatus.getShard());
      assertEquals(10, qStatus.getResult().size());
      for(Object obj : qStatus.getResult()) {
        Map<String, Object> map = (Map<String, Object>) obj;
        assertEquals(randomStr, map.get("strCol"));
      }
    }
  }
View Full Code Here

          partition = (int) (Math.random() * rowIdsPerPartition.keySet().size());
          // ... pick a random rowId from the partition
          long randomRowId = (long) (Math.random() * rowIdsPerPartition.get(partition));
          // ... query a random row
          String query = "SELECT * FROM pagecounts WHERE rowid = " + randomRowId;
          QueryStatus st = client.query(TABLESPACE, null, query, partition + "");
          if(st.getResult() != null && st.getResult().size() > 0) {
            Map<String, Object> obj = (Map<String, Object>) st.getResult().get(
                (int) (Math.random() * st.getResult().size()));
            // get the pagename
            pageToQuery = (String) obj.get("pagename");
            // some pagenames may have & characters which are not automatically encoded by SploutClient...
            pageToQuery = URLEncoder.encode(pageToQuery.replaceAll(Pattern.quote("'"), "''"), "UTF-8");
          }
          return 1;
        } else {
          // State Automata: If pageToQuery is not null, perform a GROUP BY query and set the page again to null...
          String query;
          if(querySequence == 0) {
            query = "SELECT SUM(pageviews) AS totalpageviews, date FROM pagecounts WHERE pagename = '"
                + pageToQuery + "' GROUP BY date;";
          } else {
            query = "SELECT SUM(pageviews) AS totalpageviews, hour FROM pagecounts WHERE pagename = '"
                + pageToQuery + "' GROUP BY hour;";
          }
          QueryStatus st = client.query(TABLESPACE, null, query, partition + "");
          querySequence++;
          if(querySequence == 2) {
            pageToQuery = null;
            querySequence = 0;
          }

          if(st.getResult() != null) {
            return st.getResult().size();
          } else {
            System.err.println("Query with no results (" + query + ") - please fix this error.");
            return 0;
//            throw new RuntimeException("Query with no results - that's impossible!");
          }
View Full Code Here

      this.context = context;
      client = new SploutClient(20*1000, ((String)context.get("qnodes")).split(","));
      String query = "SELECT stn, wban FROM stations";
      System.out.println("Retrieving stations list");
      long statTime = System.currentTimeMillis();
      QueryStatus st = client.query(tablespace, "any", query, null);
      if(st.getResult() == null) {
        throw new RuntimeException("Impossible to retrieve stations list. " + st);
      }
      stations = st.getResult();
      System.out.println("Loaded " + stations.size() + " stations in "
          + (System.currentTimeMillis() - statTime) + " ms.");
    }
View Full Code Here

        } else {
          query = "select year,month,min(min) as min,max(max) as max from meteo where stn=" + stn
              + " and wban=" + wban + " group by year,month order by year,month";
        }

        QueryStatus st = client.query(tablespace, stn + "" + wban, query, null);
        if(st.getResult() != null) {
          return st.getResult().size();
        } else {
          return 0;
        }
    }
View Full Code Here

    try {
      qnode.start(SploutConfiguration.getTestConfig(), QNODE_HANDLER);
     
      SploutClient client = new SploutClient(qnode.getAddress());
     
      QueryStatus queryStatus = client.query("t1", "k1", "SELECT * FROM foo;", null);
      assertEquals("t1 k1 SELECT * FROM foo;", queryStatus.getError());
     
      queryStatus = client.queryPost("t1", "k1", "SELECT * FROM foo;", null);
      assertEquals("t1 k1 SELECT * FROM foo;", queryStatus.getError());

      List<String> dnodes = client.dNodeList();
      assertEquals("ok", dnodes.get(0));

      DeployInfo info = client.deploy("t1", PartitionMap.oneShardOpenedMap(), ReplicationMap.oneToOneMap("http://localhost:4444"), new URI("file:///foo"));
View Full Code Here

    for(QNode qnode : getqNodes()) {
      // Make sure all QNodes are aware of the the first deploy
      // There might be some delay as they have to receive notifications via Hazelcast etc
      long waitedSoFar = 0;
      QueryStatus status = null;
      SploutClient perQNodeClient = new SploutClient(qnode.getAddress());
      do {
        status = perQNodeClient.query(TABLESPACE, "0", "SELECT * FROM " + TABLE + ";", null);
        Thread.sleep(100);
        waitedSoFar += 100;
        if(waitedSoFar > 5000) {
          throw new AssertionError("Waiting too much on a test condition");
        }
      } while(status == null || status.getError() != null);
      log.info("QNode [" + qnode.getAddress() + "] is ready to serve deploy 0.");
    }

    try {
      // Business logic here
      ExecutorService service = Executors.newFixedThreadPool(N_THREADS);

      // These threads will continuously perform queries and check that the results is consistent.
      // They will also count how many deploys have happened since the beginning.
      for(int i = 0; i < N_THREADS; i++) {
        service.submit(new Runnable() {
          @Override
          public void run() {
            try {
              while(true) {
                int randomDNode = Math.abs(random.nextInt()) % N_DNODES;
                QueryStatus status = client.query(TABLESPACE, (randomDNode * 10) + "", "SELECT * FROM "
                    + TABLE + ";", null);
                log.info("Query status -> " + status);
                assertEquals(1, status.getResult().size());
                Map<String, Object> jsonResult = (Map<String, Object>) status.getResult().get(0);
                Integer seenIteration = (Integer) jsonResult.get("iteration");
                synchronized(iterationsSeen) {
                  iterationsSeen.add(seenIteration);
                }
                assertTrue(seenIteration <= iteration.get());
View Full Code Here

   
    for(QNode qnode : getqNodes()) {
      // Make sure all QNodes are aware of the the first deploy
      // There might be some delay as they have to receive notifications via Hazelcast etc
      long waitedSoFar = 0;
      QueryStatus status = null;
      SploutClient perQNodeClient = new SploutClient(qnode.getAddress());
      do {
        status = perQNodeClient.query(TABLESPACE, "0", "SELECT * FROM " + TABLE + ";", null);
        Thread.sleep(100);
        waitedSoFar += 100;
        if(waitedSoFar > 5000) {
          throw new AssertionError("Waiting too much on a test condition");
        }
      } while(status == null || status.getError() != null);
      log.info("QNode [" + qnode.getAddress() + "] is ready to serve deploy 0.");
    }

    try {
      // Business logic here
      ExecutorService service = Executors.newFixedThreadPool(N_THREADS);

      // This is the "mother-fucker" thread.
      // It will bring DNodes down on purpose.
      // And then bring them up again.
      service.submit(new Runnable() {

        @Override
        public void run() {

          while(true) {
            try {
              Thread.sleep(1000);
              log.info("Time to kill some DNode...");
              int whichOne = (int) (Math.random() * getdNodes().size());
              getdNodes().get(whichOne).testCommand(TestCommands.SHUTDOWN.toString());
              Thread.sleep(1000);
              log.info("Time to bring the DNode back to life...");
              getdNodes().get(whichOne).testCommand(TestCommands.RESTART.toString());
            } catch(InterruptedException e) {
              log.info("MFT - Bye bye!");
            } catch(DNodeException e) {
              failed.set(true);
              e.printStackTrace();
              throw new RuntimeException(e);
            } catch(TException e) {
              failed.set(true);
              e.printStackTrace();
              throw new RuntimeException(e);
            }
          }
        }

      });

      // These threads will continuously perform queries and check that the results are consistent.
      for(int i = 0; i < N_THREADS; i++) {
        service.submit(new Runnable() {
          @SuppressWarnings("unchecked")
          @Override
          public void run() {
            try {
              while(true) {
                int randomDNode = Math.abs(random.nextInt()) % N_DNODES;
                QueryStatus status = client.query(TABLESPACE, ((randomDNode * 10) - 1) + "", "SELECT * FROM "
                    + TABLE + ";", null);
                log.info("Query status -> " + status);
                assertEquals(1, status.getResult().size());
                Map<String, Object> jsonResult = (Map<String, Object>) status.getResult().get(0);
                assertEquals(randomDNode, jsonResult.get("dnode"));
                Thread.sleep(100);
              }
            } catch(InterruptedException ie) {
              // Bye bye
View Full Code Here

TOP

Related Classes of com.splout.db.qnode.beans.QueryStatus

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.