2 * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
9 package org.opendaylight.controller.sal.binding.codegen.impl;
11 import com.google.common.util.concurrent.ListeningExecutorService;
12 import java.lang.reflect.Field;
13 import java.util.concurrent.BlockingQueue;
14 import java.util.concurrent.ThreadPoolExecutor;
15 import java.util.concurrent.TimeUnit;
16 import org.junit.Ignore;
17 import org.junit.Test;
18 import org.slf4j.Logger;
19 import org.slf4j.LoggerFactory;
22 public class SingletonHolderTest {
23 private static final Logger logger = LoggerFactory.getLogger(SingletonHolderTest.class);
26 public void testNotificationExecutor() throws Exception {
27 ListeningExecutorService executor = SingletonHolder.getDefaultNotificationExecutor();
28 ThreadPoolExecutor tpExecutor = (ThreadPoolExecutor) setAccessible(executor.getClass().getDeclaredField("delegate")).get(executor);
29 BlockingQueue<Runnable> queue = tpExecutor.getQueue();
31 for (int idx = 0; idx < 100; idx++) {
33 logger.info("Adding {}\t{}\t{}", idx, queue.size(), tpExecutor.getActiveCount());
34 executor.execute(new Runnable() {
38 logger.info("in {}", idx2);
41 } catch (InterruptedException e) {
44 logger.info("out {}", idx2);
49 executor.awaitTermination(10, TimeUnit.SECONDS);
52 private static Field setAccessible(Field field) {
53 field.setAccessible(true);