Package org.cyclop.model

Examples of org.cyclop.model.QueryEntry$Adapter


    {
      QueryHistory history = new QueryHistory();

      for (int i = 0; i < 600; i++) {
        CqlQuery query = new CqlQuery(CqlQueryType.SELECT, "select * from MyTable1 where id=" + i);
        history.add(new QueryEntry(query, 4563));
      }
      assertEquals(500, history.size());
      testHistRange(history, 599, 100);
      storage.store(userId, history);
    }

    {
      Optional<QueryHistory> history = storage.read(userId, QueryHistory.class);
      assertNotNull(history);
      assertEquals(500, history.get().size());
      testHistRange(history.get(), 599, 100);

      for (int i = 0; i < 10; i++) {
        CqlQuery query = new CqlQuery(CqlQueryType.SELECT, "select * from MyTable2 where id=" + i);
        history.get().add(new QueryEntry(query, 567));
      }
      storage.store(userId, history.get());
    }

    {
      QueryHistory history = storage.read(userId, QueryHistory.class).get();
      assertNotNull(history);
      assertEquals(500, history.size());

      try (QueryHistory.HistoryIterator hit = history.iterator()) {
        for (int i = 9; i >= 0; i--) {
          assertTrue(hit.hasNext());
          QueryEntry entry = hit.next();
          assertTrue(history.contains(entry));
          assertNotNull(entry.executedOnUtc);
          assertEquals("select * from MyTable2 where id=" + i, entry.query.part);
        }
        for (int i = 599; i > 110; i--) {
          assertTrue(hit.hasNext());
          QueryEntry entry = hit.next();
          assertTrue(history.contains(entry));
          assertNotNull(entry.executedOnUtc);
          assertEquals("select * from MyTable1 where id=" + i, entry.query.part);
        }
      }
View Full Code Here


  @Test
  public void testCreateReadAndClear() throws Exception {
    QueryFavourites favourites = favService.read();

    for (int i = 0; i < 20; i++) {
      assertTrue(favourites.addWithSizeCheck(new QueryEntry(new CqlQuery(CqlQueryType.SELECT,
          "select * from HistoryStarTest where id=" + i), 1000 + i)));

      assertTrue(favourites.addWithSizeCheck(new QueryEntry(new CqlQuery(CqlQueryType.SELECT,
          "select * from HistoryStarTest where id=" + i), 2000 + i)));

      favService.store(favourites);
      QueryFavourites favQueue = asyncFileStore.getFromWriteQueue(user).get();
      assertNotNull(favQueue);

      // should be the same instance
      assertSame(favourites, favQueue);
    }
    assertEquals(20, favourites.size());

    assertFalse(storage.read(user, QueryFavourites.class).isPresent());

    asyncFileStore.flush();
    assertFalse(asyncFileStore.getFromWriteQueue(user).isPresent());

    assertSame(favourites, favService.read());

    QueryFavourites readFavs = storage.read(user, QueryFavourites.class).get();
    assertNotSame(favourites, readFavs);

    {
      for (int i = 0; i < 20; i++) {
        QueryEntry entry = new QueryEntry(new CqlQuery(CqlQueryType.SELECT,
            "select * from HistoryStarTest where id=" + i), 4000 + i);
        assertTrue(entry.toString(), readFavs.contains(entry));
      }
    }

    {
      favourites.clear();
View Full Code Here

        public Void call() throws Exception {
          for (int i = 0; i < repeatInTest; i++) {
            QueryFavourites readFavs = favService.read();
            favs.add(readFavs);

            QueryEntry fav = new QueryEntry(new CqlQuery(CqlQueryType.SELECT,
                "select * from MyTable2 where id=" + UUID.randomUUID()), 5000 + i);
            int retry = 0;
            while (!readFavs.addWithSizeCheck(fav)) {
              retry++;
              assertTrue(retry < 100);

              ImmutableSortedSet<QueryEntry> favsSorted = readFavs.copyAsSortedSet();
              UnmodifiableIterator<QueryEntry> iterator = favsSorted.iterator();
              QueryEntry toRemove = null;
              for (int a = 0; a < favsSorted.size(); a++) {
                toRemove = iterator.next();
              }
              readFavs.remove(toRemove);
            }
View Full Code Here

  @Test
  public void testCreateReadAndClear() throws Exception {
    QueryHistory history = historyService.read();

    for (int i = 0; i < 600; i++) {
      historyService.addAndStore(new QueryEntry(new CqlQuery(CqlQueryType.SELECT, "select * " + CR
          + "from HistoryTest where " + CR + "id=" + i), 1000 + i));
      QueryHistory historyQueue = asyncFileStore.getFromWriteQueue(user).get();
      assertNotNull(historyQueue);

      // should be the same instance
      assertSame(history, historyQueue);
    }
    assertEquals(500, history.size());

    asyncFileStore.flush();
    assertFalse(asyncFileStore.getFromWriteQueue(user).isPresent());

    assertSame(history, historyService.read());

    QueryHistory readHist = storage.read(user, QueryHistory.class).get();
    assertNotSame(history, readHist);

    for (int i = 100; i < 600; i++) {
      QueryEntry tofind = new QueryEntry(new CqlQuery(CqlQueryType.SELECT, "select * from HistoryTest where id="
          + i), 2000 + i);
      assertTrue(tofind + " NOT FOUND IN: " + readHist, readHist.contains(tofind));

      ImmutableList<QueryEntry> readList = readHist.copyAsList();
      int index = readList.indexOf(tofind);
      assertTrue(index >= 0);
      QueryEntry read = readList.get(index);
      assertNotNull(read.executedOnUtc);
      assertEquals(1000 + i, read.runTime);
    }

    {
View Full Code Here

    historyService.addAndStore(null);
  }

  @Test(expected = BeanValidationException.class)
  public void testAddAndStore_InvalidParams() {
    historyService.addAndStore(new QueryEntry(new CqlQuery(null, null), 1));
  }
View Full Code Here

        public Void call() throws Exception {
          for (int i = 0; i < repeatInTest; i++) {
            QueryHistory history = historyService.read();
            histories.add(history);

            QueryEntry histEntry = new QueryEntry(new CqlQuery(CqlQueryType.SELECT,
                "select * from MyTable2 where id=" + UUID.randomUUID()), 4000 + i);
            history.add(histEntry);

            verifyHistEntry(history, histEntry);

View Full Code Here

TOP

Related Classes of org.cyclop.model.QueryEntry$Adapter

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.