Package org.cyclop.model

Examples of org.cyclop.model.QueryFavourites$Adapter


    return QueryFavourites.class;
  }

  @Override
  protected QueryFavourites createEmpty() {
    return new QueryFavourites();
  }
View Full Code Here


    }
  }

  @Test
  public void testEmptyFavourites() {
    QueryFavourites hist = new QueryFavourites();
    assertEquals(0, hist.size());
    assertFalse(hist.copyAsSortedSet().iterator().hasNext());

    CqlQuery query = new CqlQuery(CqlQueryType.SELECT, "select * from MyTable");
    QueryEntry histEntry = new QueryEntry(query, 6456);
    assertFalse(hist.contains(histEntry));
    try {
      hist.copyAsSortedSet().iterator().next();
      fail();
    } catch (NoSuchElementException e) {
      // OK
    }
  }
View Full Code Here

  }

  @Test
  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);
View Full Code Here

  }

  @Test
  public void testLimitFavourites() {
    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

  @Before
  public void setup() throws Exception {
    super.setup();
    asyncFileStore.flush();

    QueryFavourites favs = favService.read();
    assertNotNull(favs);
    favs.clear();

    assertEquals(0, favs.size());

    user = favService.getUser();
    assertNotNull(user);
    assertNotNull(user.id);
  }
View Full Code Here

    assertNotNull(user.id);
  }

  @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

      tasks.add(new Callable<Void>() {

        @Override
        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);
            }

            verifyHistEntry(readFavs, fav);

            favService.store(readFavs);
            if (i % 20 == 0) {
              asyncFileStore.flush();
            }

            QueryFavourites readHist = favService.read();
            verifyHistEntry(readHist, fav);

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

TOP

Related Classes of org.cyclop.model.QueryFavourites$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.