Search in sources :

Example 71 with CountDownLatch

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

the class TestResourceManagerAdministrationProtocolPBClientImpl method setUpResourceManager.

/**
   * Start resource manager server
   */
@BeforeClass
public static void setUpResourceManager() throws IOException, InterruptedException {
    Configuration.addDefaultResource("config-with-security.xml");
    Configuration configuration = new YarnConfiguration();
    resourceManager = new ResourceManager() {

        @Override
        protected void doSecureLogin() throws IOException {
        }
    };
    // a reliable way to wait for resource manager to fully start
    final CountDownLatch rmStartedSignal = new CountDownLatch(1);
    ServiceStateChangeListener rmStateChangeListener = new ServiceStateChangeListener() {

        @Override
        public void stateChanged(Service service) {
            if (service.getServiceState() == STATE.STARTED) {
                rmStartedSignal.countDown();
            }
        }
    };
    resourceManager.registerServiceListener(rmStateChangeListener);
    resourceManager.init(configuration);
    new Thread() {

        public void run() {
            resourceManager.start();
        }
    }.start();
    boolean rmStarted = rmStartedSignal.await(60000L, TimeUnit.MILLISECONDS);
    Assert.assertTrue("ResourceManager failed to start up.", rmStarted);
    LOG.info("ResourceManager RMAdmin address: " + configuration.get(YarnConfiguration.RM_ADMIN_ADDRESS));
    client = new ResourceManagerAdministrationProtocolPBClientImpl(1L, getProtocolAddress(configuration), configuration);
}
Also used : YarnConfiguration(org.apache.hadoop.yarn.conf.YarnConfiguration) Configuration(org.apache.hadoop.conf.Configuration) YarnConfiguration(org.apache.hadoop.yarn.conf.YarnConfiguration) ServiceStateChangeListener(org.apache.hadoop.service.ServiceStateChangeListener) Service(org.apache.hadoop.service.Service) ResourceManager(org.apache.hadoop.yarn.server.resourcemanager.ResourceManager) IOException(java.io.IOException) CountDownLatch(java.util.concurrent.CountDownLatch) ResourceManagerAdministrationProtocolPBClientImpl(org.apache.hadoop.yarn.server.api.impl.pb.client.ResourceManagerAdministrationProtocolPBClientImpl) BeforeClass(org.junit.BeforeClass)

Example 72 with CountDownLatch

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

the class TestGetGroups method setUpResourceManager.

@BeforeClass
public static void setUpResourceManager() throws InterruptedException {
    conf = new YarnConfiguration();
    resourceManager = new ResourceManager() {

        @Override
        protected void doSecureLogin() throws IOException {
        }

        ;
    };
    // a reliable way to wait for resource manager to start
    CountDownLatch rmStartedSignal = new CountDownLatch(1);
    ServiceStateChangeListener rmStateChangeListener = new ServiceStateChangeListener() {

        @Override
        public void stateChanged(Service service) {
            if (service.getServiceState() == STATE.STARTED) {
                rmStartedSignal.countDown();
            }
        }
    };
    resourceManager.registerServiceListener(rmStateChangeListener);
    resourceManager.init(conf);
    new Thread() {

        public void run() {
            resourceManager.start();
        }

        ;
    }.start();
    boolean rmStarted = rmStartedSignal.await(60000L, TimeUnit.MILLISECONDS);
    Assert.assertTrue("ResourceManager failed to start up.", rmStarted);
    LOG.info("ResourceManager RMAdmin address: " + conf.get(YarnConfiguration.RM_ADMIN_ADDRESS));
}
Also used : YarnConfiguration(org.apache.hadoop.yarn.conf.YarnConfiguration) ServiceStateChangeListener(org.apache.hadoop.service.ServiceStateChangeListener) Service(org.apache.hadoop.service.Service) ResourceManager(org.apache.hadoop.yarn.server.resourcemanager.ResourceManager) IOException(java.io.IOException) CountDownLatch(java.util.concurrent.CountDownLatch) BeforeClass(org.junit.BeforeClass)

Example 73 with CountDownLatch

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

the class TestAggregatedLogFormat method writeSrcFileAndALog.

private void writeSrcFileAndALog(Path srcFilePath, String fileName, final long length, Path remoteAppLogFile, Path srcFileRoot, ContainerId testContainerId) throws Exception {
    File dir = new File(srcFilePath.toString());
    if (!dir.exists()) {
        if (!dir.mkdirs()) {
            throw new IOException("Unable to create directory : " + dir);
        }
    }
    File outputFile = new File(new File(srcFilePath.toString()), fileName);
    FileOutputStream os = new FileOutputStream(outputFile);
    final OutputStreamWriter osw = new OutputStreamWriter(os, "UTF8");
    final int ch = filler;
    UserGroupInformation ugi = UserGroupInformation.getCurrentUser();
    LogWriter logWriter = new LogWriter(new Configuration(), remoteAppLogFile, ugi);
    LogKey logKey = new LogKey(testContainerId);
    LogValue logValue = spy(new LogValue(Collections.singletonList(srcFileRoot.toString()), testContainerId, ugi.getShortUserName()));
    final CountDownLatch latch = new CountDownLatch(1);
    Thread t = new Thread() {

        public void run() {
            try {
                for (int i = 0; i < length / 3; i++) {
                    osw.write(ch);
                }
                latch.countDown();
                for (int i = 0; i < (2 * length) / 3; i++) {
                    osw.write(ch);
                }
                osw.close();
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }
    };
    t.start();
    //Wait till the osw is partially written
    //aggregation starts once the ows has completed 1/3rd of its work
    latch.await();
    //Aggregate The Logs
    logWriter.append(logKey, logValue);
    logWriter.close();
}
Also used : Configuration(org.apache.hadoop.conf.Configuration) LogValue(org.apache.hadoop.yarn.logaggregation.AggregatedLogFormat.LogValue) LogWriter(org.apache.hadoop.yarn.logaggregation.AggregatedLogFormat.LogWriter) FileOutputStream(java.io.FileOutputStream) LogKey(org.apache.hadoop.yarn.logaggregation.AggregatedLogFormat.LogKey) OutputStreamWriter(java.io.OutputStreamWriter) IOException(java.io.IOException) CountDownLatch(java.util.concurrent.CountDownLatch) File(java.io.File) UserGroupInformation(org.apache.hadoop.security.UserGroupInformation)

Example 74 with CountDownLatch

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

the class TestGridMixClasses method testSerialReaderThread.

/*
   * test SerialJobFactory
   */
@Test(timeout = 120000)
public void testSerialReaderThread() throws Exception {
    Configuration conf = new Configuration();
    File fin = new File("src" + File.separator + "test" + File.separator + "resources" + File.separator + "data" + File.separator + "wordcount2.json");
    // read couple jobs from wordcount2.json
    JobStoryProducer jobProducer = new ZombieJobProducer(new Path(fin.getAbsolutePath()), null, conf);
    CountDownLatch startFlag = new CountDownLatch(1);
    UserResolver resolver = new SubmitterUserResolver();
    FakeJobSubmitter submitter = new FakeJobSubmitter();
    File ws = new File("target" + File.separator + this.getClass().getName());
    if (!ws.exists()) {
        Assert.assertTrue(ws.mkdirs());
    }
    SerialJobFactory jobFactory = new SerialJobFactory(submitter, jobProducer, new Path(ws.getAbsolutePath()), conf, startFlag, resolver);
    Path ioPath = new Path(ws.getAbsolutePath());
    jobFactory.setDistCacheEmulator(new DistributedCacheEmulator(conf, ioPath));
    Thread test = jobFactory.createReaderThread();
    test.start();
    Thread.sleep(1000);
    // SerialReaderThread waits startFlag
    assertEquals(0, submitter.getJobs().size());
    // start!
    startFlag.countDown();
    while (test.isAlive()) {
        Thread.sleep(1000);
        jobFactory.update(null);
    }
    // submitter was called twice
    assertEquals(2, submitter.getJobs().size());
}
Also used : JobStoryProducer(org.apache.hadoop.tools.rumen.JobStoryProducer) Path(org.apache.hadoop.fs.Path) ZombieJobProducer(org.apache.hadoop.tools.rumen.ZombieJobProducer) Configuration(org.apache.hadoop.conf.Configuration) CountDownLatch(java.util.concurrent.CountDownLatch) File(java.io.File) Test(org.junit.Test)

Example 75 with CountDownLatch

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

the class TestNodeStatusUpdater method testConcurrentAccessToSystemCredentials.

@Test
public void testConcurrentAccessToSystemCredentials() {
    final Map<ApplicationId, ByteBuffer> testCredentials = new HashMap<>();
    ByteBuffer byteBuffer = ByteBuffer.wrap(new byte[300]);
    ApplicationId applicationId = ApplicationId.newInstance(123456, 120);
    testCredentials.put(applicationId, byteBuffer);
    final List<Throwable> exceptions = Collections.synchronizedList(new ArrayList<Throwable>());
    final int NUM_THREADS = 10;
    final CountDownLatch allDone = new CountDownLatch(NUM_THREADS);
    final ExecutorService threadPool = HadoopExecutors.newFixedThreadPool(NUM_THREADS);
    final AtomicBoolean stop = new AtomicBoolean(false);
    try {
        for (int i = 0; i < NUM_THREADS; i++) {
            threadPool.submit(new Runnable() {

                @Override
                public void run() {
                    try {
                        for (int i = 0; i < 100 && !stop.get(); i++) {
                            NodeHeartbeatResponse nodeHeartBeatResponse = newNodeHeartbeatResponse(0, NodeAction.NORMAL, null, null, null, null, 0);
                            nodeHeartBeatResponse.setSystemCredentialsForApps(testCredentials);
                            NodeHeartbeatResponseProto proto = ((NodeHeartbeatResponsePBImpl) nodeHeartBeatResponse).getProto();
                            Assert.assertNotNull(proto);
                        }
                    } catch (Throwable t) {
                        exceptions.add(t);
                        stop.set(true);
                    } finally {
                        allDone.countDown();
                    }
                }
            });
        }
        int testTimeout = 2;
        Assert.assertTrue("Timeout waiting for more than " + testTimeout + " " + "seconds", allDone.await(testTimeout, TimeUnit.SECONDS));
    } catch (InterruptedException ie) {
        exceptions.add(ie);
    } finally {
        threadPool.shutdownNow();
    }
    Assert.assertTrue("Test failed with exception(s)" + exceptions, exceptions.isEmpty());
}
Also used : YarnServerBuilderUtils.newNodeHeartbeatResponse(org.apache.hadoop.yarn.server.utils.YarnServerBuilderUtils.newNodeHeartbeatResponse) NodeHeartbeatResponse(org.apache.hadoop.yarn.server.api.protocolrecords.NodeHeartbeatResponse) HashMap(java.util.HashMap) NodeHeartbeatResponseProto(org.apache.hadoop.yarn.proto.YarnServerCommonServiceProtos.NodeHeartbeatResponseProto) CountDownLatch(java.util.concurrent.CountDownLatch) ByteBuffer(java.nio.ByteBuffer) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) ExecutorService(java.util.concurrent.ExecutorService) ApplicationId(org.apache.hadoop.yarn.api.records.ApplicationId) Test(org.junit.Test)

Aggregations

CountDownLatch (java.util.concurrent.CountDownLatch)5355 Test (org.junit.Test)2594 IOException (java.io.IOException)631 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)550 AtomicReference (java.util.concurrent.atomic.AtomicReference)501 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)475 ArrayList (java.util.ArrayList)471 QuickTest (com.hazelcast.test.annotation.QuickTest)375 ParallelTest (com.hazelcast.test.annotation.ParallelTest)355 ExecutorService (java.util.concurrent.ExecutorService)322 Test (org.testng.annotations.Test)310 HazelcastInstance (com.hazelcast.core.HazelcastInstance)251 List (java.util.List)212 HashMap (java.util.HashMap)207 HttpServletResponse (javax.servlet.http.HttpServletResponse)207 ExecutionException (java.util.concurrent.ExecutionException)203 HttpServletRequest (javax.servlet.http.HttpServletRequest)189 Ignite (org.apache.ignite.Ignite)188 ServletException (javax.servlet.ServletException)183 TimeoutException (java.util.concurrent.TimeoutException)168