Examples of QueryEntry


Examples of org.cyclop.model.QueryEntry

  public void testCreateAndRead_SingleHistoryEntry() {
    UserIdentifier userId = new UserIdentifier(UUID.randomUUID());
    QueryHistory newHistory = new QueryHistory();

    CqlQuery query = new CqlQuery(CqlQueryType.SELECT, "select * from MyTable");
    QueryEntry histEntry = new QueryEntry(query, 6645);
    newHistory.add(histEntry);

    storage.store(userId, newHistory);

    Optional<QueryHistory> readHistory = storage.read(userId, QueryHistory.class);
    assertNotNull(readHistory);
    assertEquals(1, readHistory.get().size());
    int idx = 0;
    List<QueryEntry> histList = readHistory.get().copyAsList();
    try (QueryHistory.HistoryIterator historyIterator = readHistory.get().iterator()) {
      assertTrue(historyIterator.hasNext());
      QueryEntry readEntry = historyIterator.next();
      assertEquals(histList.get(idx++), readEntry);
      assertEquals(query, readEntry.query);
      assertEquals(histEntry.executedOnUtc.toString(), readEntry.executedOnUtc.toString());

      assertEquals(0, storage.getLockRetryCount());
View Full Code Here

Examples of org.cyclop.model.QueryEntry

  public void testCreateAndRead_SingleFavouritesEntry() {
    UserIdentifier userId = new UserIdentifier(UUID.randomUUID());
    QueryFavourites newHistory = new QueryFavourites();

    CqlQuery query = new CqlQuery(CqlQueryType.SELECT, "select * from MyTable");
    QueryEntry favEntry = new QueryEntry(query, 234);
    newHistory.addWithSizeCheck(favEntry);

    storage.store(userId, newHistory);

    Optional<QueryFavourites> readHistory = storage.read(userId, QueryFavourites.class);
    assertNotNull(readHistory);
    assertEquals(1, readHistory.get().size());
    assertTrue(readHistory.get().copyAsSortedSet().iterator().hasNext());
    QueryEntry readEntry = readHistory.get().copyAsSortedSet().iterator().next();
    assertEquals(query, readEntry.query);
    assertEquals(favEntry.executedOnUtc.toString(), readEntry.executedOnUtc.toString());
    assertEquals(0, storage.getLockRetryCount());
  }
View Full Code Here

Examples of org.cyclop.model.QueryEntry

    UserIdentifier userId = new UserIdentifier(UUID.randomUUID());
    QueryFavourites history = new QueryFavourites();
    {
      for (int i = 0; i < 50; i++) {
        CqlQuery query = new CqlQuery(CqlQueryType.SELECT, "select * from MyTable where id=" + i);
        assertTrue(history.addWithSizeCheck(new QueryEntry(query, 234)));
      }
      assertEquals(50, history.size());
    }

    checkFavLimitContent(history);

    {
      for (int i = 0; i < 10; i++) {
        CqlQuery query = new CqlQuery(CqlQueryType.SELECT, "select * from MyTableA where id=" + i);
        assertFalse(history.addWithSizeCheck(new QueryEntry(query, 456)));
      }
      checkFavLimitContent(history);
    }

    {
      for (int i = 0; i < 20; i++) {
        CqlQuery query = new CqlQuery(CqlQueryType.SELECT, "select * from MyTable where id=" + i);
        assertTrue(history.addWithSizeCheck(new QueryEntry(query, 234)));
      }
      checkFavLimitContent(history);
    }

    {
View Full Code Here

Examples of org.cyclop.model.QueryEntry

    assertEquals(50, fav.size());
    assertEquals(50, history.size());
    for (int i = 0; i < 50; i++) {
      assertTrue(favIt.hasNext());
      CqlQuery query = new CqlQuery(CqlQueryType.SELECT, "select * from MyTable where id=" + i);
      assertTrue(history.contains(new QueryEntry(query, 7754)));
      assertTrue(history.contains(favIt.next()));
    }
  }
View Full Code Here

Examples of org.cyclop.model.QueryEntry

  private void testHistRange(QueryHistory history, int from, int to) {
    try (QueryHistory.HistoryIterator hit = history.iterator()) {
      for (int i = from; i >= to; 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

Examples of org.cyclop.model.QueryEntry

    {
      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

Examples of org.cyclop.model.QueryEntry

  @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

Examples of org.cyclop.model.QueryEntry

        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

Examples of org.cyclop.model.QueryEntry

  @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

Examples of org.cyclop.model.QueryEntry

    historyService.addAndStore(null);
  }

  @Test(expected = BeanValidationException.class)
  public void testAddAndStore_InvalidParams() {
    historyService.addAndStore(new QueryEntry(new CqlQuery(null, null), 1));
  }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.