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);
}
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);
}
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;
}
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);
}
}
}
}
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;
}
Aggregations