use of java.util.EnumSet in project Gaffer by gchq.
the class TableUtilsTest method shouldCreateTableCorrectlyIfSchemaContainsNoAggregators.
@Test
public void shouldCreateTableCorrectlyIfSchemaContainsNoAggregators() throws Exception {
// Given
final MockAccumuloStore store = new MockAccumuloStore();
final Schema schema = new Schema.Builder().type(TestTypes.ID_STRING, String.class).type(TestTypes.DIRECTED_TRUE, Boolean.class).edge(TestGroups.EDGE, new SchemaEdgeDefinition.Builder().source(TestTypes.ID_STRING).destination(TestTypes.ID_STRING).directed(TestTypes.DIRECTED_TRUE).build()).build();
final AccumuloProperties props = AccumuloProperties.loadStoreProperties(StreamUtil.storeProps(TableUtilsTest.class));
props.setTable(NO_AGGREGATORS_TABLE_NAME);
store.initialise(schema, props);
// When
TableUtils.createTable(store);
// Then
final Map<String, EnumSet<IteratorScope>> itrs = store.getConnection().tableOperations().listIterators(NO_AGGREGATORS_TABLE_NAME);
assertEquals(1, itrs.size());
final EnumSet<IteratorScope> validator = itrs.get(AccumuloStoreConstants.VALIDATOR_ITERATOR_NAME);
assertEquals(EnumSet.allOf(IteratorScope.class), validator);
final IteratorSetting validatorSetting = store.getConnection().tableOperations().getIteratorSetting(NO_AGGREGATORS_TABLE_NAME, AccumuloStoreConstants.VALIDATOR_ITERATOR_NAME, IteratorScope.majc);
assertEquals(AccumuloStoreConstants.VALIDATOR_ITERATOR_PRIORITY, validatorSetting.getPriority());
assertEquals(ValidatorFilter.class.getName(), validatorSetting.getIteratorClass());
final Map<String, String> validatorOptions = validatorSetting.getOptions();
assertNotNull(Schema.fromJson(validatorOptions.get(AccumuloStoreConstants.SCHEMA).getBytes(CommonConstants.UTF_8)).getEdge(TestGroups.EDGE));
assertEquals(ByteEntityAccumuloElementConverter.class.getName(), validatorOptions.get(AccumuloStoreConstants.ACCUMULO_ELEMENT_CONVERTER_CLASS));
final EnumSet<IteratorScope> aggregator = itrs.get(AccumuloStoreConstants.AGGREGATOR_ITERATOR_NAME);
assertNull(aggregator);
final IteratorSetting aggregatorSetting = store.getConnection().tableOperations().getIteratorSetting(NO_AGGREGATORS_TABLE_NAME, AccumuloStoreConstants.AGGREGATOR_ITERATOR_NAME, IteratorScope.majc);
assertNull(aggregatorSetting);
final Map<String, String> tableProps = new HashMap<>();
for (final Map.Entry<String, String> entry : store.getConnection().tableOperations().getProperties(NO_AGGREGATORS_TABLE_NAME)) {
tableProps.put(entry.getKey(), entry.getValue());
}
assertEquals(0, Integer.parseInt(tableProps.get(Property.TABLE_FILE_REPLICATION.getKey())));
}
use of java.util.EnumSet in project hadoop by apache.
the class TestApplicationMasterService method testResourceTypes.
@Test(timeout = 3000000)
public void testResourceTypes() throws Exception {
HashMap<YarnConfiguration, EnumSet<SchedulerResourceTypes>> driver = new HashMap<YarnConfiguration, EnumSet<SchedulerResourceTypes>>();
CapacitySchedulerConfiguration csconf = new CapacitySchedulerConfiguration();
csconf.setResourceComparator(DominantResourceCalculator.class);
YarnConfiguration testCapacityDRConf = new YarnConfiguration(csconf);
testCapacityDRConf.setClass(YarnConfiguration.RM_SCHEDULER, CapacityScheduler.class, ResourceScheduler.class);
YarnConfiguration testCapacityDefConf = new YarnConfiguration();
testCapacityDefConf.setClass(YarnConfiguration.RM_SCHEDULER, CapacityScheduler.class, ResourceScheduler.class);
YarnConfiguration testFairDefConf = new YarnConfiguration();
testFairDefConf.setClass(YarnConfiguration.RM_SCHEDULER, FairScheduler.class, ResourceScheduler.class);
driver.put(conf, EnumSet.of(SchedulerResourceTypes.MEMORY));
driver.put(testCapacityDRConf, EnumSet.of(SchedulerResourceTypes.CPU, SchedulerResourceTypes.MEMORY));
driver.put(testCapacityDefConf, EnumSet.of(SchedulerResourceTypes.MEMORY));
driver.put(testFairDefConf, EnumSet.of(SchedulerResourceTypes.MEMORY, SchedulerResourceTypes.CPU));
for (Map.Entry<YarnConfiguration, EnumSet<SchedulerResourceTypes>> entry : driver.entrySet()) {
EnumSet<SchedulerResourceTypes> expectedValue = entry.getValue();
MockRM rm = new MockRM(entry.getKey());
rm.start();
MockNM nm1 = rm.registerNode("127.0.0.1:1234", 6 * GB);
RMApp app1 = rm.submitApp(2048);
//Wait to make sure the attempt has the right state
//TODO explore a better way than sleeping for a while (YARN-4929)
Thread.sleep(1000);
nm1.nodeHeartbeat(true);
RMAppAttempt attempt1 = app1.getCurrentAppAttempt();
MockAM am1 = rm.sendAMLaunched(attempt1.getAppAttemptId());
RegisterApplicationMasterResponse resp = am1.registerAppAttempt();
EnumSet<SchedulerResourceTypes> types = resp.getSchedulerResourceTypes();
LOG.info("types = " + types.toString());
Assert.assertEquals(expectedValue, types);
rm.stop();
}
}
use of java.util.EnumSet in project j2objc by google.
the class EnumSetTest method test_containsAll_LCollection.
/**
* @tests java.util.EnumSet#containsAll(Collection)
*/
@SuppressWarnings({ "unchecked", "boxing" })
public void test_containsAll_LCollection() {
EnumSet<EnumFoo> set = EnumSet.noneOf(EnumFoo.class);
Enum[] elements = EnumFoo.class.getEnumConstants();
for (int i = 0; i < elements.length; i++) {
set.add((EnumFoo) elements[i]);
}
try {
set.containsAll(null);
//$NON-NLS-1$
fail("Should throw NullPointerException");
} catch (NullPointerException e) {
// expected
}
EnumSet<EmptyEnum> emptySet = EnumSet.noneOf(EmptyEnum.class);
elements = EmptyEnum.class.getEnumConstants();
for (int i = 0; i < elements.length; i++) {
emptySet.add((EmptyEnum) elements[i]);
}
boolean result = set.containsAll(emptySet);
//$NON-NLS-1$
assertTrue("Should return true", result);
Collection rawCollection = new ArrayList();
result = set.containsAll(rawCollection);
//$NON-NLS-1$
assertTrue("Should contain empty collection:", result);
rawCollection.add(1);
result = set.containsAll(rawCollection);
//$NON-NLS-1$
assertFalse("Should return false", result);
rawCollection.add(EnumWithInnerClass.a);
result = set.containsAll(rawCollection);
//$NON-NLS-1$
assertFalse("Should return false", result);
EnumSet rawSet = EnumSet.noneOf(EnumFoo.class);
result = set.containsAll(rawSet);
//$NON-NLS-1$
assertTrue("Should contain empty set", result);
emptySet = EnumSet.noneOf(EmptyEnum.class);
result = set.containsAll(emptySet);
//$NON-NLS-1$
assertTrue("No class cast should be performed on empty set", result);
Collection<EnumFoo> collection = new ArrayList<EnumFoo>();
collection.add(EnumFoo.a);
result = set.containsAll(collection);
//$NON-NLS-1$
assertTrue("Should contain all elements in collection", result);
EnumSet<EnumFoo> fooSet = EnumSet.noneOf(EnumFoo.class);
fooSet.add(EnumFoo.a);
result = set.containsAll(fooSet);
//$NON-NLS-1$
assertTrue("Should return true", result);
set.clear();
try {
set.containsAll(null);
//$NON-NLS-1$
fail("Should throw NullPointerException");
} catch (NullPointerException e) {
// expected
}
Collection<EnumWithInnerClass> collectionWithSubclass = new ArrayList<EnumWithInnerClass>();
collectionWithSubclass.add(EnumWithInnerClass.a);
result = set.containsAll(collectionWithSubclass);
//$NON-NLS-1$
assertFalse("Should return false", result);
EnumSet<EnumWithInnerClass> setWithSubclass = EnumSet.noneOf(EnumWithInnerClass.class);
setWithSubclass.add(EnumWithInnerClass.a);
result = set.containsAll(setWithSubclass);
//$NON-NLS-1$
assertFalse("Should return false", result);
// test enum type with more than 64 elements
Set<HugeEnum> hugeSet = EnumSet.noneOf(HugeEnum.class);
hugeSet.add(HugeEnum.a);
hugeSet.add(HugeEnum.b);
hugeSet.add(HugeEnum.aa);
hugeSet.add(HugeEnum.bb);
hugeSet.add(HugeEnum.cc);
hugeSet.add(HugeEnum.dd);
Set<HugeEnum> anotherHugeSet = EnumSet.noneOf(HugeEnum.class);
hugeSet.add(HugeEnum.b);
hugeSet.add(HugeEnum.cc);
result = hugeSet.containsAll(anotherHugeSet);
assertTrue(result);
try {
hugeSet.containsAll(null);
//$NON-NLS-1$
fail("Should throw NullPointerException");
} catch (NullPointerException e) {
// expected
}
Set<HugeEnumWithInnerClass> hugeSetWithInnerClass = EnumSet.noneOf(HugeEnumWithInnerClass.class);
hugeSetWithInnerClass.add(HugeEnumWithInnerClass.a);
hugeSetWithInnerClass.add(HugeEnumWithInnerClass.b);
result = hugeSetWithInnerClass.containsAll(hugeSetWithInnerClass);
assertTrue(result);
result = hugeSet.containsAll(hugeSetWithInnerClass);
assertFalse(result);
rawCollection = new ArrayList();
result = hugeSet.containsAll(rawCollection);
//$NON-NLS-1$
assertTrue("Should contain empty collection:", result);
rawCollection.add(1);
result = hugeSet.containsAll(rawCollection);
//$NON-NLS-1$
assertFalse("Should return false", result);
rawCollection.add(EnumWithInnerClass.a);
result = set.containsAll(rawCollection);
//$NON-NLS-1$
assertFalse("Should return false", result);
rawSet = EnumSet.noneOf(HugeEnum.class);
result = hugeSet.containsAll(rawSet);
//$NON-NLS-1$
assertTrue("Should contain empty set", result);
EnumSet<HugeEnumWithInnerClass> emptyHugeSet = EnumSet.noneOf(HugeEnumWithInnerClass.class);
result = hugeSet.containsAll(emptyHugeSet);
//$NON-NLS-1$
assertTrue("No class cast should be performed on empty set", result);
Collection<HugeEnum> hugeCollection = new ArrayList<HugeEnum>();
hugeCollection.add(HugeEnum.a);
result = hugeSet.containsAll(hugeCollection);
//$NON-NLS-1$
assertTrue("Should contain all elements in collection", result);
hugeSet.clear();
try {
hugeSet.containsAll(null);
//$NON-NLS-1$
fail("Should throw NullPointerException");
} catch (NullPointerException e) {
// expected
}
Collection<HugeEnumWithInnerClass> hugeCollectionWithSubclass = new ArrayList<HugeEnumWithInnerClass>();
hugeCollectionWithSubclass.add(HugeEnumWithInnerClass.a);
result = hugeSet.containsAll(hugeCollectionWithSubclass);
//$NON-NLS-1$
assertFalse("Should return false", result);
EnumSet<HugeEnumWithInnerClass> hugeSetWithSubclass = EnumSet.noneOf(HugeEnumWithInnerClass.class);
hugeSetWithSubclass.add(HugeEnumWithInnerClass.a);
result = hugeSet.containsAll(hugeSetWithSubclass);
//$NON-NLS-1$
assertFalse("Should return false", result);
}
use of java.util.EnumSet in project presto by prestodb.
the class AccumuloTableManager method setIterator.
public void setIterator(String table, IteratorSetting setting) {
try {
// Remove any existing iterator settings of the same name, if applicable
Map<String, EnumSet<IteratorScope>> iterators = connector.tableOperations().listIterators(table);
if (iterators.containsKey(setting.getName())) {
connector.tableOperations().removeIterator(table, setting.getName(), iterators.get(setting.getName()));
}
connector.tableOperations().attachIterator(table, setting);
} catch (AccumuloSecurityException | AccumuloException e) {
throw new PrestoException(UNEXPECTED_ACCUMULO_ERROR, "Failed to set iterator on table " + table, e);
} catch (TableNotFoundException e) {
throw new PrestoException(ACCUMULO_TABLE_DNE, "Failed to set iterator, table does not exist", e);
}
}
use of java.util.EnumSet in project HearthStats.net-Uploader by HearthStats.
the class ScreenAnalyser method matchScreensForTesting.
@SuppressWarnings("unchecked")
EnumSet<Screen>[] matchScreensForTesting(BufferedImage image) {
if (expectedWidth != image.getWidth() || expectedHeight != image.getHeight()) {
pixelMap = calculatePixelPositions(image.getWidth(), image.getHeight());
expectedWidth = image.getWidth();
expectedHeight = image.getHeight();
}
EnumSet<Screen> primaryMatches = EnumSet.noneOf(Screen.class);
EnumSet<Screen> secondaryMatches = EnumSet.noneOf(Screen.class);
for (Screen screen : Screen.values()) {
if (checkForExactMatch(image, screen)) {
primaryMatches.add(screen);
if (checkForMatchSecondary(image, screen)) {
secondaryMatches.add(screen);
}
}
}
return new EnumSet[] { primaryMatches, secondaryMatches };
}
Aggregations