Search in sources :

Example 51 with SortedSet

use of java.util.SortedSet in project cdap by caskdata.

the class KeyValueTableTest method testBatchReads.

@Test
public void testBatchReads() throws Exception {
    DatasetId tBatch = DatasetFrameworkTestUtil.NAMESPACE_ID.dataset("tBatch");
    dsFrameworkUtil.createInstance("keyValueTable", tBatch, DatasetProperties.EMPTY);
    final KeyValueTable t = dsFrameworkUtil.getInstance(tBatch);
    TransactionExecutor txnl = dsFrameworkUtil.newTransactionExecutor(t);
    final SortedSet<Long> keysWritten = Sets.newTreeSet();
    // start a transaction
    txnl.execute(new TransactionExecutor.Subroutine() {

        @Override
        public void apply() throws Exception {
            // write 1000 random values to the table and remember them in a set
            Random rand = new Random(451);
            for (int i = 0; i < 1000; i++) {
                long keyLong = rand.nextLong();
                byte[] key = Bytes.toBytes(keyLong);
                t.write(key, key);
                keysWritten.add(keyLong);
            }
        }
    });
    // start a sync transaction
    txnl.execute(new TransactionExecutor.Subroutine() {

        @Override
        public void apply() throws Exception {
            // get the splits for the table
            List<Split> splits = t.getSplits();
            // read each split and verify the keys
            SortedSet<Long> keysToVerify = Sets.newTreeSet(keysWritten);
            verifySplits(t, splits, keysToVerify);
        }
    });
    // start a sync transaction
    txnl.execute(new TransactionExecutor.Subroutine() {

        @Override
        public void apply() throws Exception {
            // get specific number of splits for a subrange
            SortedSet<Long> keysToVerify = Sets.newTreeSet(keysWritten.subSet(0x10000000L, 0x40000000L));
            List<Split> splits = t.getSplits(5, Bytes.toBytes(0x10000000L), Bytes.toBytes(0x40000000L));
            Assert.assertTrue(splits.size() <= 5);
            // read each split and verify the keys
            verifySplits(t, splits, keysToVerify);
        }
    });
    dsFrameworkUtil.deleteInstance(tBatch);
}
Also used : Random(java.util.Random) TransactionExecutor(org.apache.tephra.TransactionExecutor) List(java.util.List) SortedSet(java.util.SortedSet) TransactionFailureException(org.apache.tephra.TransactionFailureException) NoSuchElementException(java.util.NoSuchElementException) DatasetId(co.cask.cdap.proto.id.DatasetId) Test(org.junit.Test)

Example 52 with SortedSet

use of java.util.SortedSet in project cdap by caskdata.

the class ObjectStoreDatasetTest method testBatchReads.

@Test
public void testBatchReads() throws Exception {
    DatasetId batch = DatasetFrameworkTestUtil.NAMESPACE_ID.dataset("batch");
    createObjectStoreInstance(batch, String.class);
    final ObjectStoreDataset<String> t = dsFrameworkUtil.getInstance(batch);
    TransactionExecutor txnl = dsFrameworkUtil.newTransactionExecutor(t);
    final SortedSet<Long> keysWritten = Sets.newTreeSet();
    // write 1000 random values to the table and remember them in a set
    txnl.execute(new TransactionExecutor.Subroutine() {

        @Override
        public void apply() throws Exception {
            Random rand = new Random(451);
            for (int i = 0; i < 1000; i++) {
                long keyLong = rand.nextLong();
                byte[] key = Bytes.toBytes(keyLong);
                t.write(key, Long.toString(keyLong));
                keysWritten.add(keyLong);
            }
        }
    });
    txnl.execute(new TransactionExecutor.Subroutine() {

        @Override
        public void apply() throws Exception {
            // get the splits for the table
            List<Split> splits = t.getSplits();
            // read each split and verify the keys
            SortedSet<Long> keysToVerify = Sets.newTreeSet(keysWritten);
            verifySplits(t, splits, keysToVerify);
        }
    });
    txnl.execute(new TransactionExecutor.Subroutine() {

        @Override
        public void apply() throws Exception {
            // get specific number of splits for a subrange
            TreeSet<Long> keysToVerify = Sets.newTreeSet(keysWritten.subSet(0x10000000L, 0x40000000L));
            List<Split> splits = t.getSplits(5, Bytes.toBytes(0x10000000L), Bytes.toBytes(0x40000000L));
            Assert.assertTrue(splits.size() <= 5);
            // read each split and verify the keys
            verifySplits(t, splits, keysToVerify);
        }
    });
    deleteAndVerifyInBatch(t, txnl, keysWritten);
    dsFrameworkUtil.deleteInstance(batch);
}
Also used : TransactionExecutor(org.apache.tephra.TransactionExecutor) SortedSet(java.util.SortedSet) ImmutableSortedSet(com.google.common.collect.ImmutableSortedSet) TransactionFailureException(org.apache.tephra.TransactionFailureException) NoSuchElementException(java.util.NoSuchElementException) DatasetId(co.cask.cdap.proto.id.DatasetId) Random(java.util.Random) TreeSet(java.util.TreeSet) List(java.util.List) Test(org.junit.Test)

Example 53 with SortedSet

use of java.util.SortedSet in project processdash by dtuma.

the class AbstractLabelColumn method getValuesInUse.

protected Set<String> getValuesInUse() {
    SortedSet values = new TreeSet();
    collectValuesInUse(values, wbsModel.getRoot());
    return values;
}
Also used : TreeSet(java.util.TreeSet) SortedSet(java.util.SortedSet)

Example 54 with SortedSet

use of java.util.SortedSet in project gatk by broadinstitute.

the class RecalibrationReport method logTablesWithMissingReadGroups.

/**
     * helper function to output log messages if there are tables that are missing read groups that were seen in the other tables
     * @param allReadGroups a set of all of the read groups across inputs
     * @param inputReadGroups a map from file to the read groups that file contains
     */
private static void logTablesWithMissingReadGroups(SortedSet<String> allReadGroups, Map<File, Set<String>> inputReadGroups) {
    // Log the read groups that are missing from specific inputs
    for (final Map.Entry<File, Set<String>> entry : inputReadGroups.entrySet()) {
        final File input = entry.getKey();
        final Set<String> readGroups = entry.getValue();
        if (allReadGroups.size() != readGroups.size()) {
            // Since this is not completely unexpected, more than debug, but less than a proper warning.
            logger.info("Missing read group(s)" + ": " + input.getAbsolutePath());
            for (final Object readGroup : CollectionUtils.subtract(allReadGroups, readGroups)) {
                logger.info("  " + readGroup);
            }
        }
    }
}
Also used : SortedSet(java.util.SortedSet) TreeSet(java.util.TreeSet) Set(java.util.Set) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) File(java.io.File)

Example 55 with SortedSet

use of java.util.SortedSet in project bnd by bndtools.

the class Project method getBundlesWildcard.

/**
	 * Get all bundles matching a wildcard expression.
	 *
	 * @param bsnPattern A bsn wildcard, e.g. "osgi*" or just "*".
	 * @param range A range to narrow the versions of bundles found, or null to
	 *            return any version.
	 * @param strategyx The version selection strategy, which may be 'HIGHEST'
	 *            or 'LOWEST' only -- 'EXACT' is not permitted.
	 * @param attrs Additional search attributes.
	 * @throws Exception
	 */
public List<Container> getBundlesWildcard(String bsnPattern, String range, Strategy strategyx, Map<String, String> attrs) throws Exception {
    if (VERSION_ATTR_SNAPSHOT.equals(range) || VERSION_ATTR_PROJECT.equals(range))
        return Collections.singletonList(new Container(this, bsnPattern, range, TYPE.ERROR, null, "Cannot use snapshot or project version with wildcard matches", null, null));
    if (strategyx == Strategy.EXACT)
        return Collections.singletonList(new Container(this, bsnPattern, range, TYPE.ERROR, null, "Cannot use exact version strategy with wildcard matches", null, null));
    VersionRange versionRange;
    if (range == null || VERSION_ATTR_LATEST.equals(range))
        versionRange = new VersionRange("0");
    else
        versionRange = new VersionRange(range);
    RepoFilter repoFilter = parseRepoFilter(attrs);
    if (bsnPattern != null) {
        bsnPattern = bsnPattern.trim();
        if (bsnPattern.length() == 0 || bsnPattern.equals("*"))
            bsnPattern = null;
    }
    SortedMap<String, Pair<Version, RepositoryPlugin>> providerMap = new TreeMap<String, Pair<Version, RepositoryPlugin>>();
    List<RepositoryPlugin> plugins = workspace.getRepositories();
    for (RepositoryPlugin plugin : plugins) {
        if (repoFilter != null && !repoFilter.match(plugin))
            continue;
        List<String> bsns = plugin.list(bsnPattern);
        if (bsns != null)
            for (String bsn : bsns) {
                SortedSet<Version> versions = plugin.versions(bsn);
                if (versions != null && !versions.isEmpty()) {
                    Pair<Version, RepositoryPlugin> currentProvider = providerMap.get(bsn);
                    Version candidate;
                    switch(strategyx) {
                        case HIGHEST:
                            candidate = versions.last();
                            if (currentProvider == null || candidate.compareTo(currentProvider.getFirst()) > 0) {
                                providerMap.put(bsn, new Pair<Version, RepositoryPlugin>(candidate, plugin));
                            }
                            break;
                        case LOWEST:
                            candidate = versions.first();
                            if (currentProvider == null || candidate.compareTo(currentProvider.getFirst()) < 0) {
                                providerMap.put(bsn, new Pair<Version, RepositoryPlugin>(candidate, plugin));
                            }
                            break;
                        default:
                            // we shouldn't have reached this point!
                            throw new IllegalStateException("Cannot use exact version strategy with wildcard matches");
                    }
                }
            }
    }
    List<Container> containers = new ArrayList<Container>(providerMap.size());
    for (Entry<String, Pair<Version, RepositoryPlugin>> entry : providerMap.entrySet()) {
        String bsn = entry.getKey();
        Version version = entry.getValue().getFirst();
        RepositoryPlugin repo = entry.getValue().getSecond();
        DownloadBlocker downloadBlocker = new DownloadBlocker(this);
        File bundle = repo.get(bsn, version, attrs, downloadBlocker);
        if (bundle != null && !bundle.getName().endsWith(".lib")) {
            containers.add(new Container(this, bsn, range, Container.TYPE.REPO, bundle, null, attrs, downloadBlocker));
        }
    }
    return containers;
}
Also used : ArrayList(java.util.ArrayList) RepositoryPlugin(aQute.bnd.service.RepositoryPlugin) VersionRange(aQute.bnd.version.VersionRange) TreeMap(java.util.TreeMap) SortedSet(java.util.SortedSet) Version(aQute.bnd.version.Version) File(java.io.File) Pair(aQute.libg.tuple.Pair)

Aggregations

SortedSet (java.util.SortedSet)127 TreeSet (java.util.TreeSet)49 Iterator (java.util.Iterator)43 HashMap (java.util.HashMap)24 NavigableSet (java.util.NavigableSet)22 ArrayList (java.util.ArrayList)20 Map (java.util.Map)20 List (java.util.List)19 Set (java.util.Set)19 TreeMap (java.util.TreeMap)18 HashSet (java.util.HashSet)15 Test (org.junit.Test)13 IOException (java.io.IOException)12 Collection (java.util.Collection)10 Comparator (java.util.Comparator)7 LinkedHashMap (java.util.LinkedHashMap)7 LinkedList (java.util.LinkedList)5 SolverException (cbit.vcell.solver.SolverException)3 TestStringSortedSetGenerator (com.google.common.collect.testing.TestStringSortedSetGenerator)3 File (java.io.File)3