Search in sources :

Example 41 with EnumSet

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())));
}
Also used : MockAccumuloStore(uk.gov.gchq.gaffer.accumulostore.MockAccumuloStore) SingleUseMockAccumuloStore(uk.gov.gchq.gaffer.accumulostore.SingleUseMockAccumuloStore) AccumuloProperties(uk.gov.gchq.gaffer.accumulostore.AccumuloProperties) HashMap(java.util.HashMap) Schema(uk.gov.gchq.gaffer.store.schema.Schema) EnumSet(java.util.EnumSet) ValidatorFilter(uk.gov.gchq.gaffer.accumulostore.key.impl.ValidatorFilter) IteratorSetting(org.apache.accumulo.core.client.IteratorSetting) ByteEntityAccumuloElementConverter(uk.gov.gchq.gaffer.accumulostore.key.core.impl.byteEntity.ByteEntityAccumuloElementConverter) IteratorScope(org.apache.accumulo.core.iterators.IteratorUtil.IteratorScope) HashMap(java.util.HashMap) Map(java.util.Map) Test(org.junit.Test)

Example 42 with EnumSet

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();
    }
}
Also used : RMApp(org.apache.hadoop.yarn.server.resourcemanager.rmapp.RMApp) RMAppAttempt(org.apache.hadoop.yarn.server.resourcemanager.rmapp.attempt.RMAppAttempt) HashMap(java.util.HashMap) EnumSet(java.util.EnumSet) SchedulerResourceTypes(org.apache.hadoop.yarn.proto.YarnServiceProtos.SchedulerResourceTypes) YarnConfiguration(org.apache.hadoop.yarn.conf.YarnConfiguration) RegisterApplicationMasterResponse(org.apache.hadoop.yarn.api.protocolrecords.RegisterApplicationMasterResponse) HashMap(java.util.HashMap) Map(java.util.Map) CapacitySchedulerConfiguration(org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.CapacitySchedulerConfiguration) Test(org.junit.Test)

Example 43 with EnumSet

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);
}
Also used : EnumSet(java.util.EnumSet) ArrayList(java.util.ArrayList) Collection(java.util.Collection)

Example 44 with EnumSet

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);
    }
}
Also used : AccumuloException(org.apache.accumulo.core.client.AccumuloException) TableNotFoundException(org.apache.accumulo.core.client.TableNotFoundException) EnumSet(java.util.EnumSet) AccumuloSecurityException(org.apache.accumulo.core.client.AccumuloSecurityException) PrestoException(com.facebook.presto.spi.PrestoException)

Example 45 with EnumSet

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 };
}
Also used : Screen(net.hearthstats.game.Screen) EnumSet(java.util.EnumSet)

Aggregations

EnumSet (java.util.EnumSet)65 Map (java.util.Map)18 Set (java.util.Set)18 ArrayList (java.util.ArrayList)13 HashMap (java.util.HashMap)13 HashSet (java.util.HashSet)12 Test (org.junit.Test)10 TreeSet (java.util.TreeSet)7 Collection (java.util.Collection)6 List (java.util.List)6 ParseUtils.unexpectedElement (org.jboss.as.controller.parsing.ParseUtils.unexpectedElement)6 LinkedHashSet (java.util.LinkedHashSet)5 TreeMap (java.util.TreeMap)5 StateStorage.toStringStringSetMap (org.apache.karaf.features.internal.service.StateStorage.toStringStringSetMap)5 PathAddress (org.jboss.as.controller.PathAddress)5 PathElement (org.jboss.as.controller.PathElement)5 ModelNode (org.jboss.dmr.ModelNode)5 IOException (java.io.IOException)4 FeatureState (org.apache.karaf.features.FeatureState)4 Collections (java.util.Collections)3