Search in sources :

Example 1 with Configuration

use of org.apache.accumulo.core.spi.common.ServiceEnvironment.Configuration in project accumulo by apache.

the class DefaultCompactionPlannerTest method createPlanner.

private static DefaultCompactionPlanner createPlanner(boolean withHugeExecutor) {
    DefaultCompactionPlanner planner = new DefaultCompactionPlanner();
    Configuration conf = EasyMock.createMock(Configuration.class);
    EasyMock.expect(conf.isSet(EasyMock.anyString())).andReturn(false).anyTimes();
    ServiceEnvironment senv = EasyMock.createMock(ServiceEnvironment.class);
    EasyMock.expect(senv.getConfiguration()).andReturn(conf).anyTimes();
    EasyMock.replay(conf, senv);
    StringBuilder execBldr = new StringBuilder("[{'name':'small','type': 'internal','maxSize':'32M','numThreads':1}," + "{'name':'medium','type': 'internal','maxSize':'128M','numThreads':2}," + "{'name':'large','type': 'internal','maxSize':'512M','numThreads':3}");
    if (withHugeExecutor) {
        execBldr.append(",{'name':'huge','type': 'internal','numThreads':4}]");
    } else {
        execBldr.append("]");
    }
    String executors = execBldr.toString().replaceAll("'", "\"");
    planner.init(new CompactionPlanner.InitParameters() {

        @Override
        public ServiceEnvironment getServiceEnvironment() {
            return senv;
        }

        @Override
        public Map<String, String> getOptions() {
            return Map.of("executors", executors, "maxOpen", "15");
        }

        @Override
        public String getFullyQualifiedOption(String key) {
            assertEquals("maxOpen", key);
            return Property.TSERV_COMPACTION_SERVICE_PREFIX.getKey() + "cs1.planner.opts." + key;
        }

        @Override
        public ExecutorManager getExecutorManager() {
            return new ExecutorManager() {

                @Override
                public CompactionExecutorId createExecutor(String name, int threads) {
                    switch(name) {
                        case "small":
                            assertEquals(1, threads);
                            break;
                        case "medium":
                            assertEquals(2, threads);
                            break;
                        case "large":
                            assertEquals(3, threads);
                            break;
                        case "huge":
                            assertEquals(4, threads);
                            break;
                        default:
                            fail("Unexpected name " + name);
                            break;
                    }
                    return CompactionExecutorIdImpl.externalId(name);
                }

                @Override
                public CompactionExecutorId getExternalExecutor(String name) {
                    throw new UnsupportedOperationException();
                }
            };
        }
    });
    return planner;
}
Also used : Configuration(org.apache.accumulo.core.spi.common.ServiceEnvironment.Configuration) ServiceEnvironment(org.apache.accumulo.core.spi.common.ServiceEnvironment) Map(java.util.Map)

Example 2 with Configuration

use of org.apache.accumulo.core.spi.common.ServiceEnvironment.Configuration in project accumulo by apache.

the class DefaultCompactionPlannerTest method testErrorOnlyOneMaxSize.

/**
 * Tests executors can only have one without a max size.
 */
@Test
public void testErrorOnlyOneMaxSize() {
    DefaultCompactionPlanner planner = new DefaultCompactionPlanner();
    Configuration conf = EasyMock.createMock(Configuration.class);
    EasyMock.expect(conf.isSet(EasyMock.anyString())).andReturn(false).anyTimes();
    ServiceEnvironment senv = EasyMock.createMock(ServiceEnvironment.class);
    EasyMock.expect(senv.getConfiguration()).andReturn(conf).anyTimes();
    EasyMock.replay(conf, senv);
    String executors = getExecutors("'type': 'internal','maxSize':'32M','numThreads':1", "'type': 'internal','numThreads':2", "'type': 'external','queue':'q1'");
    var e = assertThrows(IllegalArgumentException.class, () -> planner.init(getInitParams(senv, executors)), "Failed to throw error");
    assertTrue(e.getMessage().contains("maxSize"), "Error message didn't contain maxSize");
}
Also used : ServiceEnvironment(org.apache.accumulo.core.spi.common.ServiceEnvironment) Configuration(org.apache.accumulo.core.spi.common.ServiceEnvironment.Configuration) Test(org.junit.jupiter.api.Test)

Example 3 with Configuration

use of org.apache.accumulo.core.spi.common.ServiceEnvironment.Configuration in project accumulo by apache.

the class DefaultCompactionPlannerTest method testErrorInternalTypeNoNumThreads.

/**
 * Tests internal type executor with no numThreads set throws error
 */
@Test
public void testErrorInternalTypeNoNumThreads() {
    DefaultCompactionPlanner planner = new DefaultCompactionPlanner();
    Configuration conf = EasyMock.createMock(Configuration.class);
    EasyMock.expect(conf.isSet(EasyMock.anyString())).andReturn(false).anyTimes();
    ServiceEnvironment senv = EasyMock.createMock(ServiceEnvironment.class);
    EasyMock.expect(senv.getConfiguration()).andReturn(conf).anyTimes();
    EasyMock.replay(conf, senv);
    String executors = getExecutors("'type': 'internal','maxSize':'32M'", "'type': 'internal','maxSize':'128M','numThreads':2", "'type': 'internal','maxSize':'512M','numThreads':3");
    var e = assertThrows(NullPointerException.class, () -> planner.init(getInitParams(senv, executors)), "Failed to throw error");
    assertTrue(e.getMessage().contains("numThreads"), "Error message didn't contain numThreads");
}
Also used : ServiceEnvironment(org.apache.accumulo.core.spi.common.ServiceEnvironment) Configuration(org.apache.accumulo.core.spi.common.ServiceEnvironment.Configuration) Test(org.junit.jupiter.api.Test)

Example 4 with Configuration

use of org.apache.accumulo.core.spi.common.ServiceEnvironment.Configuration in project accumulo by apache.

the class DefaultCompactionPlannerTest method testErrorDuplicateMaxSize.

/**
 * Tests executors can only have one without a max size.
 */
@Test
public void testErrorDuplicateMaxSize() {
    DefaultCompactionPlanner planner = new DefaultCompactionPlanner();
    Configuration conf = EasyMock.createMock(Configuration.class);
    EasyMock.expect(conf.isSet(EasyMock.anyString())).andReturn(false).anyTimes();
    ServiceEnvironment senv = EasyMock.createMock(ServiceEnvironment.class);
    EasyMock.expect(senv.getConfiguration()).andReturn(conf).anyTimes();
    EasyMock.replay(conf, senv);
    String executors = getExecutors("'type': 'internal','maxSize':'32M','numThreads':1", "'type': 'internal','maxSize':'128M','numThreads':2", "'type': 'external','maxSize':'128M','queue':'q1'");
    var e = assertThrows(IllegalArgumentException.class, () -> planner.init(getInitParams(senv, executors)), "Failed to throw error");
    assertTrue(e.getMessage().contains("maxSize"), "Error message didn't contain maxSize");
}
Also used : ServiceEnvironment(org.apache.accumulo.core.spi.common.ServiceEnvironment) Configuration(org.apache.accumulo.core.spi.common.ServiceEnvironment.Configuration) Test(org.junit.jupiter.api.Test)

Example 5 with Configuration

use of org.apache.accumulo.core.spi.common.ServiceEnvironment.Configuration in project accumulo by apache.

the class DefaultCompactionPlannerTest method testErrorExternalNoQueue.

/**
 * Tests external type executor missing queue throws error
 */
@Test
public void testErrorExternalNoQueue() {
    DefaultCompactionPlanner planner = new DefaultCompactionPlanner();
    Configuration conf = EasyMock.createMock(Configuration.class);
    EasyMock.expect(conf.isSet(EasyMock.anyString())).andReturn(false).anyTimes();
    ServiceEnvironment senv = EasyMock.createMock(ServiceEnvironment.class);
    EasyMock.expect(senv.getConfiguration()).andReturn(conf).anyTimes();
    EasyMock.replay(conf, senv);
    String executors = getExecutors("'type': 'internal','maxSize':'32M','numThreads':1", "'type': 'internal','maxSize':'128M','numThreads':2", "'type': 'external','maxSize':'512M'");
    var e = assertThrows(NullPointerException.class, () -> planner.init(getInitParams(senv, executors)), "Failed to throw error");
    assertTrue(e.getMessage().contains("queue"), "Error message didn't contain queue");
}
Also used : ServiceEnvironment(org.apache.accumulo.core.spi.common.ServiceEnvironment) Configuration(org.apache.accumulo.core.spi.common.ServiceEnvironment.Configuration) Test(org.junit.jupiter.api.Test)

Aggregations

Configuration (org.apache.accumulo.core.spi.common.ServiceEnvironment.Configuration)7 ServiceEnvironment (org.apache.accumulo.core.spi.common.ServiceEnvironment)6 Test (org.junit.jupiter.api.Test)5 Map (java.util.Map)1 AccumuloConfiguration (org.apache.accumulo.core.conf.AccumuloConfiguration)1