Search in sources :

Example 51 with ConcurrentHashMap

use of java.util.concurrent.ConcurrentHashMap in project mapdb by jankotek.

the class ConcurrentHashMap8Test method testMerge2.

/**
     * merge replaces when the given key is present
     */
public void testMerge2() {
    ConcurrentHashMap map = map5();
    assertEquals("Z", map.merge(one, "Y", (x, y) -> "Z"));
}
Also used : NONNULL(java.util.Spliterator.NONNULL) LongAdder(java.util.concurrent.atomic.LongAdder) Arrays(java.util.Arrays) Test(junit.framework.Test) Iterator(java.util.Iterator) Collection(java.util.Collection) BiFunction(java.util.function.BiFunction) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Set(java.util.Set) TestSuite(junit.framework.TestSuite) AbstractMap(java.util.AbstractMap) DISTINCT(java.util.Spliterator.DISTINCT) Map(java.util.Map) NoSuchElementException(java.util.NoSuchElementException) CONCURRENT(java.util.Spliterator.CONCURRENT) Collections(java.util.Collections) Spliterator(java.util.Spliterator) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap)

Example 52 with ConcurrentHashMap

use of java.util.concurrent.ConcurrentHashMap in project mapdb by jankotek.

the class ConcurrentHashMap8Test method testCompute2.

/**
     * compute adds when the given key is not present
     */
public void testCompute2() {
    ConcurrentHashMap map = map5();
    assertEquals("Z", map.compute(six, (x, y) -> "Z"));
}
Also used : NONNULL(java.util.Spliterator.NONNULL) LongAdder(java.util.concurrent.atomic.LongAdder) Arrays(java.util.Arrays) Test(junit.framework.Test) Iterator(java.util.Iterator) Collection(java.util.Collection) BiFunction(java.util.function.BiFunction) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Set(java.util.Set) TestSuite(junit.framework.TestSuite) AbstractMap(java.util.AbstractMap) DISTINCT(java.util.Spliterator.DISTINCT) Map(java.util.Map) NoSuchElementException(java.util.NoSuchElementException) CONCURRENT(java.util.Spliterator.CONCURRENT) Collections(java.util.Collections) Spliterator(java.util.Spliterator) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap)

Example 53 with ConcurrentHashMap

use of java.util.concurrent.ConcurrentHashMap in project mapdb by jankotek.

the class ConcurrentHashMap8Test method map5.

/**
     * Returns a new map from Integers 1-5 to Strings "A"-"E".
     */
private static ConcurrentHashMap map5() {
    ConcurrentHashMap map = new ConcurrentHashMap(5);
    assertTrue(map.isEmpty());
    map.put(one, "A");
    map.put(two, "B");
    map.put(three, "C");
    map.put(four, "D");
    map.put(five, "E");
    assertFalse(map.isEmpty());
    assertEquals(5, map.size());
    return map;
}
Also used : ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap)

Example 54 with ConcurrentHashMap

use of java.util.concurrent.ConcurrentHashMap in project hadoop by apache.

the class TestContainerLogsPage method testContainerLogPageAccess.

@Test(timeout = 10000)
public void testContainerLogPageAccess() throws IOException {
    // SecureIOUtils require Native IO to be enabled. This test will run
    // only if it is enabled.
    assumeTrue(NativeIO.isAvailable());
    String user = "randomUser" + System.currentTimeMillis();
    File absLogDir = null, appDir = null, containerDir = null, syslog = null;
    try {
        // target log directory
        absLogDir = new File("target", TestContainerLogsPage.class.getSimpleName() + "LogDir").getAbsoluteFile();
        absLogDir.mkdir();
        Configuration conf = new Configuration();
        conf.set(YarnConfiguration.NM_LOG_DIRS, absLogDir.toURI().toString());
        conf.set(CommonConfigurationKeysPublic.HADOOP_SECURITY_AUTHENTICATION, "kerberos");
        UserGroupInformation.setConfiguration(conf);
        NodeHealthCheckerService healthChecker = createNodeHealthCheckerService(conf);
        healthChecker.init(conf);
        LocalDirsHandlerService dirsHandler = healthChecker.getDiskHandler();
        // Add an application and the corresponding containers
        RecordFactory recordFactory = RecordFactoryProvider.getRecordFactory(conf);
        long clusterTimeStamp = 1234;
        ApplicationId appId = BuilderUtils.newApplicationId(recordFactory, clusterTimeStamp, 1);
        Application app = mock(Application.class);
        when(app.getAppId()).thenReturn(appId);
        // Making sure that application returns a random user. This is required
        // for SecureIOUtils' file owner check.
        when(app.getUser()).thenReturn(user);
        ApplicationAttemptId appAttemptId = BuilderUtils.newApplicationAttemptId(appId, 1);
        ContainerId container1 = BuilderUtils.newContainerId(recordFactory, appId, appAttemptId, 0);
        // Testing secure read access for log files
        // Creating application and container directory and syslog file.
        appDir = new File(absLogDir, appId.toString());
        appDir.mkdir();
        containerDir = new File(appDir, container1.toString());
        containerDir.mkdir();
        syslog = new File(containerDir, "syslog");
        syslog.createNewFile();
        BufferedOutputStream out = new BufferedOutputStream(new FileOutputStream(syslog));
        out.write("Log file Content".getBytes());
        out.close();
        Context context = mock(Context.class);
        ConcurrentMap<ApplicationId, Application> appMap = new ConcurrentHashMap<ApplicationId, Application>();
        appMap.put(appId, app);
        when(context.getApplications()).thenReturn(appMap);
        ConcurrentHashMap<ContainerId, Container> containers = new ConcurrentHashMap<ContainerId, Container>();
        when(context.getContainers()).thenReturn(containers);
        when(context.getLocalDirsHandler()).thenReturn(dirsHandler);
        MockContainer container = new MockContainer(appAttemptId, new AsyncDispatcher(), conf, user, appId, 1);
        container.setState(ContainerState.RUNNING);
        context.getContainers().put(container1, container);
        ContainersLogsBlock cLogsBlock = new ContainersLogsBlock(context);
        Map<String, String> params = new HashMap<String, String>();
        params.put(YarnWebParams.CONTAINER_ID, container1.toString());
        params.put(YarnWebParams.CONTAINER_LOG_TYPE, "syslog");
        Injector injector = WebAppTests.testPage(ContainerLogsPage.class, ContainersLogsBlock.class, cLogsBlock, params, (Module[]) null);
        PrintWriter spyPw = WebAppTests.getPrintWriter(injector);
        verify(spyPw).write("Exception reading log file. Application submitted by '" + user + "' doesn't own requested log file : syslog");
    } finally {
        if (syslog != null) {
            syslog.delete();
        }
        if (containerDir != null) {
            containerDir.delete();
        }
        if (appDir != null) {
            appDir.delete();
        }
        if (absLogDir != null) {
            absLogDir.delete();
        }
    }
}
Also used : Configuration(org.apache.hadoop.conf.Configuration) YarnConfiguration(org.apache.hadoop.yarn.conf.YarnConfiguration) NodeHealthCheckerService(org.apache.hadoop.yarn.server.nodemanager.NodeHealthCheckerService) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) Container(org.apache.hadoop.yarn.server.nodemanager.containermanager.container.Container) ContainerId(org.apache.hadoop.yarn.api.records.ContainerId) Injector(com.google.inject.Injector) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) BufferedOutputStream(java.io.BufferedOutputStream) PrintWriter(java.io.PrintWriter) NMContext(org.apache.hadoop.yarn.server.nodemanager.NodeManager.NMContext) Context(org.apache.hadoop.yarn.server.nodemanager.Context) ContainersLogsBlock(org.apache.hadoop.yarn.server.nodemanager.webapp.ContainerLogsPage.ContainersLogsBlock) ApplicationAttemptId(org.apache.hadoop.yarn.api.records.ApplicationAttemptId) LocalDirsHandlerService(org.apache.hadoop.yarn.server.nodemanager.LocalDirsHandlerService) RecordFactory(org.apache.hadoop.yarn.factories.RecordFactory) AsyncDispatcher(org.apache.hadoop.yarn.event.AsyncDispatcher) FileOutputStream(java.io.FileOutputStream) ApplicationId(org.apache.hadoop.yarn.api.records.ApplicationId) Module(com.google.inject.Module) File(java.io.File) Application(org.apache.hadoop.yarn.server.nodemanager.containermanager.application.Application) Test(org.junit.Test)

Example 55 with ConcurrentHashMap

use of java.util.concurrent.ConcurrentHashMap in project hadoop by apache.

the class TestLogAggregationService method createLogAggregationService.

private LogAggregationService createLogAggregationService(ApplicationId appId, String className, String parameters, boolean createLogAggContext) {
    ConcurrentHashMap<ContainerId, Container> containers = new ConcurrentHashMap<ContainerId, Container>();
    LogAggregationService logAggregationService = new LogAggregationService(dispatcher, this.context, this.delSrvc, super.dirsHandler);
    logAggregationService.init(this.conf);
    logAggregationService.start();
    LogAggregationContext logAggContext = null;
    if (createLogAggContext) {
        logAggContext = Records.newRecord(LogAggregationContext.class);
        logAggContext.setLogAggregationPolicyClassName(className);
        if (parameters != null) {
            logAggContext.setLogAggregationPolicyParameters(parameters);
        }
    }
    logAggregationService.handle(new LogHandlerAppStartedEvent(appId, this.user, null, this.acls, logAggContext));
    return logAggregationService;
}
Also used : LogHandlerAppStartedEvent(org.apache.hadoop.yarn.server.nodemanager.containermanager.loghandler.event.LogHandlerAppStartedEvent) Container(org.apache.hadoop.yarn.server.nodemanager.containermanager.container.Container) ContainerId(org.apache.hadoop.yarn.api.records.ContainerId) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) LogAggregationContext(org.apache.hadoop.yarn.api.records.LogAggregationContext)

Aggregations

ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)420 Map (java.util.Map)106 Test (org.junit.Test)102 HashMap (java.util.HashMap)75 ArrayList (java.util.ArrayList)73 CountDownLatch (java.util.concurrent.CountDownLatch)53 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)49 IOException (java.io.IOException)47 List (java.util.List)38 Set (java.util.Set)36 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)33 HashSet (java.util.HashSet)31 AtomicLong (java.util.concurrent.atomic.AtomicLong)29 ConcurrentMap (java.util.concurrent.ConcurrentMap)28 Random (java.util.Random)25 ExecutorService (java.util.concurrent.ExecutorService)23 Collection (java.util.Collection)20 UUID (java.util.UUID)20 Iterator (java.util.Iterator)19 Configuration (org.apache.hadoop.conf.Configuration)17