Merge "Bug 809: Enhancements to the toaster example"
[controller.git] / opendaylight / md-sal / sal-binding-broker / src / test / java / org / opendaylight / controller / sal / binding / codegen / impl / SingletonHolderTest.java
1 /*
2  * Copyright (c) 2014 Cisco Systems, Inc. and others.  All rights reserved.
3  *
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
7  */
8
9 package org.opendaylight.controller.sal.binding.codegen.impl;
10
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;
20
21 @Ignore
22 public class SingletonHolderTest {
23     private static final Logger logger = LoggerFactory.getLogger(SingletonHolderTest.class);
24
25     @Test
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();
30
31         for (int idx = 0; idx < 100; idx++) {
32             final int idx2 = idx;
33             logger.info("Adding {}\t{}\t{}", idx, queue.size(), tpExecutor.getActiveCount());
34             executor.execute(new Runnable() {
35
36                 @Override
37                 public void run() {
38                     logger.info("in  {}", idx2);
39                     try {
40                         Thread.sleep(1000);
41                     } catch (InterruptedException e) {
42                         e.printStackTrace();
43                     }
44                     logger.info("out {}", idx2);
45                 }
46             });
47         }
48         executor.shutdown();
49         executor.awaitTermination(10, TimeUnit.SECONDS);
50     }
51
52     private static Field setAccessible(Field field) {
53         field.setAccessible(true);
54         return field;
55     }
56 }