Add configurable connection timeout to netconf client.
[controller.git] / opendaylight / netconf / netconf-it / src / test / java / org / opendaylight / controller / netconf / it / AbstractNetconfConfigTest.java
1 /*
2  * Copyright (c) 2013 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 package org.opendaylight.controller.netconf.it;
9
10 import io.netty.channel.EventLoopGroup;
11 import io.netty.channel.nio.NioEventLoopGroup;
12 import io.netty.util.HashedWheelTimer;
13 import org.junit.After;
14 import org.junit.Before;
15 import org.opendaylight.controller.config.manager.impl.AbstractConfigTest;
16 import org.opendaylight.controller.netconf.impl.DefaultCommitNotificationProducer;
17 import org.opendaylight.controller.netconf.impl.NetconfServerDispatcher;
18 import org.opendaylight.controller.netconf.impl.NetconfServerSessionListenerFactory;
19 import org.opendaylight.controller.netconf.impl.NetconfServerSessionNegotiatorFactory;
20 import org.opendaylight.controller.netconf.impl.SessionIdProvider;
21 import org.opendaylight.controller.netconf.impl.osgi.NetconfOperationServiceFactoryListenerImpl;
22 import org.opendaylight.controller.netconf.impl.osgi.SessionMonitoringService;
23
24 public class AbstractNetconfConfigTest extends AbstractConfigTest {
25
26     protected EventLoopGroup nettyThreadgroup;
27     private HashedWheelTimer hashedWheelTimer;
28
29     @Before
30     public void setUpAbstractNetconfConfigTest() {
31         nettyThreadgroup = new NioEventLoopGroup();
32         hashedWheelTimer = new HashedWheelTimer();
33     }
34
35
36     protected NetconfServerDispatcher createDispatcher(
37             NetconfOperationServiceFactoryListenerImpl factoriesListener, SessionMonitoringService sessionMonitoringService,
38             DefaultCommitNotificationProducer commitNotifier) {
39         SessionIdProvider idProvider = new SessionIdProvider();
40
41         NetconfServerSessionNegotiatorFactory serverNegotiatorFactory = new NetconfServerSessionNegotiatorFactory(
42                 hashedWheelTimer, factoriesListener, idProvider, 5000);
43
44         NetconfServerSessionListenerFactory listenerFactory = new NetconfServerSessionListenerFactory(
45                 factoriesListener, commitNotifier, idProvider,
46                 sessionMonitoringService);
47
48         NetconfServerDispatcher.ServerChannelInitializer serverChannelInitializer = new NetconfServerDispatcher.ServerChannelInitializer(
49                 serverNegotiatorFactory, listenerFactory);
50         return new NetconfServerDispatcher(serverChannelInitializer, nettyThreadgroup, nettyThreadgroup);
51     }
52
53
54     @After
55     public void cleanUpTimer() {
56         hashedWheelTimer.stop();
57         nettyThreadgroup.shutdownGracefully();
58     }
59
60 }