Remove dependency on general-entity
[mdsal.git] / dom / mdsal-dom-inmemory-datastore / src / test / java / org / opendaylight / mdsal / dom / store / inmemory / 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 package org.opendaylight.mdsal.dom.store.inmemory;
9
10 import com.google.common.util.concurrent.ForwardingExecutorService;
11 import com.google.common.util.concurrent.MoreExecutors;
12 import java.util.concurrent.ExecutorService;
13
14 /**
15  * A forwarding Executor used by unit tests for DataChangeListener notifications.
16  *
17  * @author Thomas Pantelis
18  */
19 public class TestDCLExecutorService extends ForwardingExecutorService {
20
21     // Start with a same thread executor to avoid timing issues during test setup.
22     private volatile ExecutorService currentExecutor = MoreExecutors.newDirectExecutorService();
23
24     // The real executor to use when test setup is complete.
25     private final ExecutorService postSetupExecutor;
26
27
28     public TestDCLExecutorService(final ExecutorService postSetupExecutor) {
29         this.postSetupExecutor = postSetupExecutor;
30     }
31
32     @Override
33     protected ExecutorService delegate() {
34         return currentExecutor;
35     }
36
37     public void afterTestSetup() {
38         // Test setup complete - switch to the real executor.
39         currentExecutor = postSetupExecutor;
40     }
41 }