Merge "BUG 2718 : Create a diagnostic utility to track append entries replies"
[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 com.google.common.util.concurrent.ForwardingExecutorService;
12 import com.google.common.util.concurrent.MoreExecutors;
13 import java.util.concurrent.ExecutorService;
14
15 /**
16  * A forwarding Executor used by unit tests for DataChangeListener notifications
17  *
18  * @author Thomas Pantelis
19  */
20 public class TestDCLExecutorService extends ForwardingExecutorService {
21
22     // Start with a same thread executor to avoid timing issues during test setup.
23     private volatile ExecutorService currentExecutor = MoreExecutors.newDirectExecutorService();
24
25     // The real executor to use when test setup is complete.
26     private final ExecutorService postSetupExecutor;
27
28
29     public TestDCLExecutorService( final ExecutorService postSetupExecutor ) {
30         this.postSetupExecutor = postSetupExecutor;
31     }
32
33     @Override
34     protected ExecutorService delegate() {
35         return currentExecutor;
36     }
37
38     public void afterTestSetup() {
39         // Test setup complete - switch to the real executor.
40         currentExecutor = postSetupExecutor;
41     }
42 }