List of usage examples for java.util List containsAll
boolean containsAll(Collection<?> c);
From source file:hsa.awp.user.facade.DBUserFacadeTest.java
/** * Creates some {@link StudyCourse}s and checks if all were found by the {@link UserFacade#getAllStudyCourses()} works * correctly.//from w w w .j av a 2s . c om */ @Test public void testGetAllStudyCourses() { List<StudyCourse> created = new ArrayList<StudyCourse>(); // create some StudyCourses for (int i = 0; i < 43; i++) { created.add(facade.saveStudyCourse(StudyCourse.getInstance("UserFacadeTest" + i))); } // find all StudyCourses List<StudyCourse> found = facade.getAllStudyCourses(); // check data assertEquals(created.size(), found.size()); assertTrue(found.containsAll(created)); }
From source file:org.apache.hadoop.hbase.master.TestRegionPlacement.java
@Test public void testFavoredNodesPresentForRandomAssignment() throws HBaseIOException { LoadBalancer balancer = LoadBalancerFactory.getLoadBalancer(TEST_UTIL.getConfiguration()); balancer.setMasterServices(TEST_UTIL.getMiniHBaseCluster().getMaster()); List<ServerName> servers = new ArrayList<ServerName>(); for (int i = 0; i < SLAVES; i++) { ServerName server = TEST_UTIL.getMiniHBaseCluster().getRegionServer(i).getServerName(); servers.add(server);/*from www. j a v a 2s. co m*/ } List<HRegionInfo> regions = new ArrayList<HRegionInfo>(1); HRegionInfo region = new HRegionInfo(TableName.valueOf("foobar")); regions.add(region); ServerName serverBefore = balancer.randomAssignment(region, servers); List<ServerName> favoredNodesBefore = ((FavoredNodeLoadBalancer) balancer).getFavoredNodes(region); assertTrue(favoredNodesBefore.size() == 3); // the primary RS should be the one that the balancer's assignment returns assertTrue(ServerName.isSameHostnameAndPort(serverBefore, favoredNodesBefore.get(PRIMARY))); // now remove the primary from the list of servers removeMatchingServers(serverBefore, servers); // call randomAssignment with the modified servers list ServerName serverAfter = balancer.randomAssignment(region, servers); List<ServerName> favoredNodesAfter = ((FavoredNodeLoadBalancer) balancer).getFavoredNodes(region); assertTrue(favoredNodesAfter.size() == 3); // We don't expect the favored nodes assignments to change in multiple calls // to the randomAssignment method in the balancer (relevant for AssignmentManager.assign // failures) assertTrue(favoredNodesAfter.containsAll(favoredNodesBefore)); // We expect the new RegionServer assignee to be one of the favored nodes // chosen earlier. assertTrue(ServerName.isSameHostnameAndPort(serverAfter, favoredNodesBefore.get(SECONDARY)) || ServerName.isSameHostnameAndPort(serverAfter, favoredNodesBefore.get(TERTIARY))); // Make all the favored nodes unavailable for assignment removeMatchingServers(favoredNodesAfter, servers); // call randomAssignment with the modified servers list balancer.randomAssignment(region, servers); List<ServerName> favoredNodesNow = ((FavoredNodeLoadBalancer) balancer).getFavoredNodes(region); assertTrue(favoredNodesNow.size() == 3); assertTrue(!favoredNodesNow.contains(favoredNodesAfter.get(PRIMARY)) && !favoredNodesNow.contains(favoredNodesAfter.get(SECONDARY)) && !favoredNodesNow.contains(favoredNodesAfter.get(TERTIARY))); }
From source file:org.olat.modules.webFeed.ui.ItemsController.java
private boolean isSameAllItems(List<Item> items) { if (allItemIds == null) return false; List<ItemId> itemIds = new ArrayList<ItemId>(); for (Item item : items) { itemIds.add(new ItemId(item)); }/* w w w . j av a 2s.c om*/ return allItemIds.containsAll(itemIds) && itemIds.containsAll(allItemIds); }
From source file:org.apache.hadoop.hbase.master.TestRegionPlacement.java
@Test public void testFavoredNodesPresentForRoundRobinAssignment() throws HBaseIOException { LoadBalancer balancer = LoadBalancerFactory.getLoadBalancer(TEST_UTIL.getConfiguration()); balancer.setMasterServices(TEST_UTIL.getMiniHBaseCluster().getMaster()); List<ServerName> servers = new ArrayList<ServerName>(); for (int i = 0; i < SLAVES; i++) { ServerName server = TEST_UTIL.getMiniHBaseCluster().getRegionServer(i).getServerName(); servers.add(server);/*from w w w.j a va2 s. c o m*/ } List<HRegionInfo> regions = new ArrayList<HRegionInfo>(1); HRegionInfo region = new HRegionInfo(TableName.valueOf("foobar")); regions.add(region); Map<ServerName, List<HRegionInfo>> assignmentMap = balancer.roundRobinAssignment(regions, servers); Set<ServerName> serverBefore = assignmentMap.keySet(); List<ServerName> favoredNodesBefore = ((FavoredNodeLoadBalancer) balancer).getFavoredNodes(region); assertTrue(favoredNodesBefore.size() == 3); // the primary RS should be the one that the balancer's assignment returns assertTrue( ServerName.isSameHostnameAndPort(serverBefore.iterator().next(), favoredNodesBefore.get(PRIMARY))); // now remove the primary from the list of available servers List<ServerName> removedServers = removeMatchingServers(serverBefore, servers); // call roundRobinAssignment with the modified servers list assignmentMap = balancer.roundRobinAssignment(regions, servers); List<ServerName> favoredNodesAfter = ((FavoredNodeLoadBalancer) balancer).getFavoredNodes(region); assertTrue(favoredNodesAfter.size() == 3); // We don't expect the favored nodes assignments to change in multiple calls // to the roundRobinAssignment method in the balancer (relevant for AssignmentManager.assign // failures) assertTrue(favoredNodesAfter.containsAll(favoredNodesBefore)); Set<ServerName> serverAfter = assignmentMap.keySet(); // We expect the new RegionServer assignee to be one of the favored nodes // chosen earlier. assertTrue( ServerName.isSameHostnameAndPort(serverAfter.iterator().next(), favoredNodesBefore.get(SECONDARY)) || ServerName.isSameHostnameAndPort(serverAfter.iterator().next(), favoredNodesBefore.get(TERTIARY))); // put back the primary in the list of available servers servers.addAll(removedServers); // now roundRobinAssignment with the modified servers list should return the primary // as the regionserver assignee assignmentMap = balancer.roundRobinAssignment(regions, servers); Set<ServerName> serverWithPrimary = assignmentMap.keySet(); assertTrue(serverBefore.containsAll(serverWithPrimary)); // Make all the favored nodes unavailable for assignment removeMatchingServers(favoredNodesAfter, servers); // call roundRobinAssignment with the modified servers list assignmentMap = balancer.roundRobinAssignment(regions, servers); List<ServerName> favoredNodesNow = ((FavoredNodeLoadBalancer) balancer).getFavoredNodes(region); assertTrue(favoredNodesNow.size() == 3); assertTrue(!favoredNodesNow.contains(favoredNodesAfter.get(PRIMARY)) && !favoredNodesNow.contains(favoredNodesAfter.get(SECONDARY)) && !favoredNodesNow.contains(favoredNodesAfter.get(TERTIARY))); }
From source file:org.broadinstitute.gatk.utils.MathUtilsUnitTest.java
/** * Tests that the random index selection is working correctly *//*from w w w.ja v a2 s . co m*/ @Test public void testRandomIndicesWithReplacement() { logger.warn("Executing testRandomIndicesWithReplacement"); // Check that the size of the list returned is correct Assert.assertTrue(MathUtils.sampleIndicesWithReplacement(5, 0).size() == 0); Assert.assertTrue(MathUtils.sampleIndicesWithReplacement(5, 1).size() == 1); Assert.assertTrue(MathUtils.sampleIndicesWithReplacement(5, 5).size() == 5); Assert.assertTrue(MathUtils.sampleIndicesWithReplacement(5, 1000).size() == 1000); // Check that the list contains only the k element range that as asked for - no more, no less List<Integer> Five = new ArrayList<>(); Collections.addAll(Five, 0, 1, 2, 3, 4); List<Integer> BigFive = MathUtils.sampleIndicesWithReplacement(5, 10000); Assert.assertTrue(BigFive.containsAll(Five)); Assert.assertTrue(Five.containsAll(BigFive)); }
From source file:org.broadinstitute.gatk.utils.MathUtilsUnitTest.java
/** * Tests that we get the right values from the multinomial distribution *///from www . j a v a2 s. com @Test public void testSliceListByIndices() { logger.warn("Executing testSliceListByIndices"); // Check that the list contains only the k element range that as asked for - no more, no less but now // use the index list to pull elements from another list using sliceListByIndices List<Integer> Five = new ArrayList<>(); Collections.addAll(Five, 0, 1, 2, 3, 4); List<Character> FiveAlpha = new ArrayList<>(); Collections.addAll(FiveAlpha, 'a', 'b', 'c', 'd', 'e'); List<Integer> BigFive = MathUtils.sampleIndicesWithReplacement(5, 10000); List<Character> BigFiveAlpha = MathUtils.sliceListByIndices(BigFive, FiveAlpha); Assert.assertTrue(BigFiveAlpha.containsAll(FiveAlpha)); Assert.assertTrue(FiveAlpha.containsAll(BigFiveAlpha)); }
From source file:org.apache.kylin.cube.CubeManager.java
public void validateNewSegments(CubeInstance cube, CubeSegment newSegments) { List<CubeSegment> tobe = cube.calculateToBeSegments(newSegments); List<CubeSegment> newList = Arrays.asList(newSegments); if (tobe.containsAll(newList) == false) { throw new IllegalStateException("For cube " + cube + ", the new segments " + newList + " do not fit in its current " + cube.getSegments() + "; the resulted tobe is " + tobe); }//from w ww . j a va2 s. c om }
From source file:hsa.awp.campaign.facade.CampaignFacadeTest.java
/** * Test method for {@link hsa.awp.campaign.facade.CampaignFacade#getAllCampaigns()}. *//*from www. j a v a 2s. co m*/ @Test @Transactional public void testGetAllCampaigns() { clearCampaigns(); List<Campaign> list = new ArrayList<Campaign>(); for (int i = 0; i < 5; i++) { Campaign c = Campaign.getInstance(0L); c.setName("hallowelt" + i); c = campFac.saveCampaign(c); list.add(c); } assertTrue(list.containsAll(campFac.getAllCampaigns())); }
From source file:com.autentia.wuija.persistence.impl.hibernate.HibernateGroupManagementTest.java
@Test @Transactional/*w ww . j av a 2s . c om*/ public void test10CreateRoles() { log.trace("Entering"); // Creating roles final List<GrantedAuthority> roles = new ArrayList<GrantedAuthority>(); roles.add(new HibernateGrantedAuthority("ROLE_ADMIN")); roles.add(new HibernateGrantedAuthority("ROLE_POWER_USER")); roles.add(new HibernateGrantedAuthority("ROLE_USER")); roles.add(new HibernateGrantedAuthority("ROLE_GUEST")); dao.persist(roles); // Retrieve roles and compare with inserted ones final List<GrantedAuthority> authorities = dao .find("from " + HibernateGrantedAuthority.class.getSimpleName()); Assert.assertEquals("loaded roles size", roles.size(), authorities.size()); Assert.assertTrue("Loaded roles must be same that inserted ones", roles.containsAll(authorities)); log.trace("Exiting"); }
From source file:com.linkedin.pinot.controller.helix.sharding.SegmentAssignmentStrategyTest.java
@Test public void testPartitionLevelReplicaGroupSegmentAssignmentStrategy() throws Exception { int totalPartitionNumber = random.nextInt(8) + 2; int numInstancesPerPartition = random.nextInt(5) + 1; int numSegments = random.nextInt(10) + 10; // Create the configuration for segment assignment strategy. ReplicaGroupStrategyConfig replicaGroupStrategyConfig = new ReplicaGroupStrategyConfig(); replicaGroupStrategyConfig.setNumInstancesPerPartition(numInstancesPerPartition); replicaGroupStrategyConfig.setMirrorAssignmentAcrossReplicaGroups(false); // Now, set the partitioning column to trigger the partition level replica group assignment. replicaGroupStrategyConfig.setPartitionColumn(PARTITION_COLUMN); // Create the indexing config IndexingConfig indexingConfig = new IndexingConfig(); Map<String, ColumnPartitionConfig> partitionConfigMap = new HashMap<>(); partitionConfigMap.put(PARTITION_COLUMN, new ColumnPartitionConfig("modulo", totalPartitionNumber)); indexingConfig.setSegmentPartitionConfig(new SegmentPartitionConfig(partitionConfigMap)); // Create table config TableConfig tableConfig = new TableConfig.Builder(CommonConstants.Helix.TableType.OFFLINE) .setTableName(TABLE_NAME_PARTITION_LEVEL_REPLICA_GROUP).setNumReplicas(NUM_REPLICA) .setSegmentAssignmentStrategy("ReplicaGroupSegmentAssignmentStrategy").build(); tableConfig.getValidationConfig().setReplicaGroupStrategyConfig(replicaGroupStrategyConfig); tableConfig.setIndexingConfig(indexingConfig); // This will trigger to build the partition to replica group mapping table. _pinotHelixResourceManager.addTable(tableConfig); // Wait for table addition while (!_pinotHelixResourceManager.hasOfflineTable(TABLE_NAME_PARTITION_LEVEL_REPLICA_GROUP)) { Thread.sleep(100);//from ww w .j a v a 2 s.com } // Tracking segments that belong to a partition number. Map<Integer, Set<String>> partitionToSegment = new HashMap<>(); // Upload segments for (int i = 0; i < numSegments; ++i) { int partitionNumber = i % totalPartitionNumber; String segmentName = "segment" + i; addOneSegmentWithPartitionInfo(TABLE_NAME_PARTITION_LEVEL_REPLICA_GROUP, segmentName, PARTITION_COLUMN, partitionNumber); if (!partitionToSegment.containsKey(partitionNumber)) { partitionToSegment.put(partitionNumber, new HashSet<String>()); } partitionToSegment.get(partitionNumber).add(segmentName); } // Wait for all segments appear in the external view while (!allSegmentsPushedToIdealState(TABLE_NAME_PARTITION_LEVEL_REPLICA_GROUP, numSegments)) { Thread.sleep(100); } // Create a table of a list of segments that are assigned to a server. Map<String, Set<String>> serverToSegments = getServersToSegmentsMapping( TABLE_NAME_PARTITION_LEVEL_REPLICA_GROUP); // Fetch the replica group mapping table. String offlineTable = TableNameBuilder.OFFLINE.tableNameWithType(TABLE_NAME_PARTITION_LEVEL_REPLICA_GROUP); ReplicaGroupPartitionAssignment partitionAssignment = _partitionAssignmentGenerator .getReplicaGroupPartitionAssignment(offlineTable); // Check that each replica group for a partition contains all segments that belong to the partition. for (int partition = 0; partition < totalPartitionNumber; partition++) { for (int group = 0; group < NUM_REPLICA; group++) { List<String> serversInReplicaGroup = partitionAssignment.getInstancesfromReplicaGroup(partition, group); List<String> segmentsInReplicaGroup = new ArrayList<>(); for (String server : serversInReplicaGroup) { Set<String> segmentsInServer = serverToSegments.get(server); for (String segment : segmentsInServer) { if (partitionToSegment.get(partition).contains(segment)) { segmentsInReplicaGroup.add(segment); } } } Assert.assertEquals(segmentsInReplicaGroup.size(), partitionToSegment.get(partition).size()); Assert.assertTrue(segmentsInReplicaGroup.containsAll(partitionToSegment.get(partition))); } } }