BUG 2676 : Introduce API for accessing akka dispatchers
[controller.git] / opendaylight / md-sal / sal-inmemory-datastore / src / test / java / org / opendaylight / controller / md / sal / dom / store / impl / TestDCLExecutorService.java
1 /*
2  * Copyright (c) 2014 Brocade Communications 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.md.sal.dom.store.impl;
10
11 import java.util.concurrent.ExecutorService;
12
13 import com.google.common.util.concurrent.ForwardingExecutorService;
14 import com.google.common.util.concurrent.MoreExecutors;
15
16 /**
17  * A forwarding Executor used by unit tests for DataChangeListener notifications
18  *
19  * @author Thomas Pantelis
20  */
21 public class TestDCLExecutorService extends ForwardingExecutorService {
22
23     // Start with a same thread executor to avoid timing issues during test setup.
24     private volatile ExecutorService currentExecutor = MoreExecutors.sameThreadExecutor();
25
26     // The real executor to use when test setup is complete.
27     private final ExecutorService postSetupExecutor;
28
29
30     public TestDCLExecutorService( ExecutorService postSetupExecutor ) {
31         this.postSetupExecutor = postSetupExecutor;
32     }
33
34     @Override
35     protected ExecutorService delegate() {
36         return currentExecutor;
37     }
38
39     public void afterTestSetup() {
40         // Test setup complete - switch to the real executor.
41         currentExecutor = postSetupExecutor;
42     }
43 }