@Test
  public void shouldReturnAllMatchingTablesWhenManyTablesExist() throws Exception {
    RandomTableGenerator generator = new RandomTableGenerator();
    generator.setGameTypes("BLACKJACK", "HISSTERIA", "ROULETTE");
    Set<Table> nonMatching = generator.generateTables(100);

    generator.setGameTypes(gameType);
    generator.setTemplateNames(toMap(gameType, variation));
    generator.setClients(toMap(gameType, clientId));

    generator.setFulls(false);
    generator.setShowInLobbys(true);
    generator.setAvailableForJoinings(true);
    generator.setStatii(TableStatus.open);
    generator.setTags("tag1", "tag2", "tag3");

    Set<Table> matching = generator.generateTables(12);

    Set<Table> all = new HashSet<Table>(nonMatching);
    all.addAll(matching);
    assertEquals(112, all.size());

    gigaSpace.writeMultiple(all.toArray(new Table[all.size()]));

    Collection<TableSearchResult> found =
        tableSearchService.findTables(
            BigDecimal.TEN,
            new TableSearchCriteria(gameType, variation, clientId, Collections.<String>emptySet()));
    assertEquals(12, found.size());
  }
  @Test
  public void shouldReturnMatchingTablesWhenTagsAreSpecified() throws Exception {
    RandomTableGenerator generator = new RandomTableGenerator();
    generator.setGameTypes("BLACKJACK", "HISSTERIA", "ROULETTE");
    generator.setGameTypes(gameType);
    generator.setTemplateNames(toMap(gameType, variation));
    generator.setClients(toMap(gameType, clientId));

    generator.setFulls(false);
    generator.setShowInLobbys(true);
    generator.setAvailableForJoinings(true);
    generator.setStatii(TableStatus.open);
    generator.setTags("tag1", "tag2", "tag3");

    Set<Table> generated = generator.generateTables(12);
    Table firstTable = generated.iterator().next();
    firstTable.setTags(newHashSet("tag4"));
    gigaSpace.writeMultiple(generated.toArray(new Table[generated.size()]));

    Collection<TableSearchResult> found =
        tableSearchService.findTables(
            BigDecimal.TEN,
            new TableSearchCriteria(gameType, variation, clientId, newHashSet("tag4")));
    assertThat(found.size(), is(equalTo(1)));
    assertThat(found.iterator().next().getTableId(), is(equalTo(firstTable.getTableId())));
  }
  @Test
  public void shouldReturnEmptySetWhenPlayerIsPlayingAtOnlyTableAndTableIsExcluded()
      throws Exception {
    RandomTableGenerator generator = new RandomTableGenerator();
    generator.setGameTypes(gameType);
    generator.setTemplateNames(toMap(gameType, variation));
    generator.setClients(toMap(gameType, clientId));

    generator.setFulls(false);
    generator.setShowInLobbys(true);
    generator.setAvailableForJoinings(true);
    generator.setStatii(TableStatus.open);
    Set<Table> generated = generator.generateTables(1);
    Table tableWithPlayer = generated.iterator().next();
    tableWithPlayer.addPlayerToTable(new PlayerInformation(BigDecimal.TEN));

    generated = generator.generateTables(1);
    Table excludedTable = generated.iterator().next();
    excludedTable.setTableId(BigDecimal.valueOf(45));

    gigaSpace.writeMultiple(new Table[] {tableWithPlayer, excludedTable});

    Collection<TableSearchResult> found =
        tableSearchService.findTables(
            BigDecimal.TEN,
            new TableSearchCriteria(
                gameType,
                variation,
                clientId,
                Collections.<String>emptySet(),
                BigDecimal.valueOf(45)));

    assertEquals(0, found.size());
  }
 @Override
 public void run() {
   List<Tweet> userTimeline;
   try {
     log.info("Getting latest tweets from public timeline and feeding them into processing grid");
     // Return all the tweets from the Twitter API
     userTimeline = twitterTemplate.timelineOperations().getUserTimeline("BriefingcomSMU");
   } catch (ApiException e) {
     log.log(Level.SEVERE, "Error getting tweets from public timeline from twitter", e);
     return;
   }
   try {
     // according to the API we may get duplicate tweets if invoked with frequency of lower than 60
     // seconds.
     // We will filter tweets which are duplicates
     for (Tweet publicTweet : userTimeline) {
       if (previousTimeLineTweets.contains(publicTweet.getId())) {
         continue;
       }
       logTweet(publicTweet);
       gigaSpace.write(buildTweet(publicTweet));
     }
   } catch (DataAccessException e) {
     log.log(Level.SEVERE, "error feeding tweets", e);
   } finally {
     previousTimeLineTweets.clear();
     for (Tweet publicTweet : userTimeline) {
       previousTimeLineTweets.add(publicTweet.getId());
     }
   }
 }
 @Before
 public void setup() {
   Client client = new Client(clientId);
   client.setNumberOfSeats(10);
   when(clientRepository.findById(clientId)).thenReturn(client);
   tableSearchService =
       new GigaspaceRemotingTableSearchService(gigaSpace, clientRepository, gameRepository);
   gigaSpace.clear(new Table());
 }
  @Test
  public void shouldReturnTransformedTableOnExecute() throws Exception {
    Table expected = createTable();
    when(tableGigaSpace.read(new Table())).thenReturn(expected);

    TableSummary tableSummary = underTest.execute();

    assertEquals(expected.summarise(gameRules), tableSummary);
  }
  @Test
  public void shouldReturnOneTableWhenOnlyOneMatchesAndClientAndTemplateAreSpecified()
      throws Exception {
    RandomTableGenerator generator = new RandomTableGenerator();
    generator.setGameTypes("BLACKJACK", "HISSTERIA", "ROULETTE");
    Set<Table> nonMatching = generator.generateTables(100);

    generator.setGameTypes(gameType);
    generator.setTemplateNames(toMap(gameType, variation));
    generator.setClients(toMap(gameType, clientId));
    generator.setFulls(false);
    generator.setShowInLobbys(true);
    generator.setAvailableForJoinings(true);
    generator.setStatii(TableStatus.open);

    GameStatus gameStatus = mock(GameStatus.class);
    when(gameRepository.getGameRules(anyString())).thenReturn(gameRules);
    when(gameRules.getJoiningDesirability(gameStatus)).thenReturn(45);

    Set<Table> matching = generator.generateTables(1);
    Table generatedTable = matching.iterator().next();
    generatedTable.setTableId(BigDecimal.valueOf(67));
    generatedTable.setCurrentGame(gameStatus);

    Set<Table> all = new HashSet<Table>(nonMatching);
    all.addAll(matching);
    gigaSpace.writeMultiple(all.toArray(new Table[all.size()]));

    assertEquals(101, gigaSpace.count(new Table()));

    Collection<TableSearchResult> found =
        tableSearchService.findTables(
            BigDecimal.TEN,
            new TableSearchCriteria(gameType, variation, clientId, Collections.<String>emptySet()));

    assertEquals(1, found.size());
    TableSearchResult table = found.iterator().next();
    assertEquals(BigDecimal.valueOf(67), table.getTableId());
    assertEquals(10, table.getSpareSeats());
    assertEquals(45, table.getJoiningDesirability());
  }
  @Test
  public void shouldReturnTableWhenPlayerIsNotPlayingAtOnlyTable() throws Exception {
    RandomTableGenerator generator = new RandomTableGenerator();
    generator.setGameTypes(gameType);
    generator.setTemplateNames(toMap(gameType, variation));
    generator.setClients(toMap(gameType, clientId));

    generator.setFulls(false);
    generator.setShowInLobbys(true);
    generator.setAvailableForJoinings(true);
    generator.setStatii(TableStatus.open);

    Set<Table> generated = generator.generateTables(1);

    GameStatus gameStatus = mock(GameStatus.class);
    when(gameRepository.getGameRules(anyString())).thenReturn(gameRules);
    when(gameRules.getJoiningDesirability(gameStatus)).thenReturn(45);

    Table first = generated.iterator().next();
    first.addPlayerToTable(new PlayerInformation(BigDecimal.ONE));
    first.setTableId(BigDecimal.valueOf(67));
    first.setCurrentGame(gameStatus);

    gigaSpace.writeMultiple(generated.toArray(new Table[generated.size()]));

    Collection<TableSearchResult> found =
        tableSearchService.findTables(
            BigDecimal.TEN,
            new TableSearchCriteria(gameType, variation, clientId, Collections.<String>emptySet()));
    assertEquals(1, found.size());
    TableSearchResult table = found.iterator().next();

    assertEquals(BigDecimal.valueOf(67), table.getTableId());
    assertEquals(10, table.getSpareSeats());
    assertEquals(10, table.getMaxSeats());
    assertEquals(45, table.getJoiningDesirability());
  }
示例#9
0
 public ArrayList<SpaceDocument> fetch(GigaSpace gigaSpace) {
   return new ArrayList<>(Arrays.asList(gigaSpace.readByIds(idsQuery).getResultsArray()));
 }