import com.google.common.collect.Lists;
import com.google.common.collect.Sets;
import io.netty.channel.ChannelFuture;
+import io.netty.channel.EventLoopGroup;
+import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.util.HashedWheelTimer;
import org.junit.After;
-import org.junit.AfterClass;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
closeSession, startExi, stopExi;
private DefaultCommitNotificationProducer commitNot;
private NetconfServerDispatcher dispatch;
+ private EventLoopGroup nettyThreadgroup;
- private static NetconfClientDispatcher NETCONF_CLIENT_DISPATCHER = new NetconfClientDispatcher(Optional.<SSLContext>absent());
+ private NetconfClientDispatcher clientDispatcher;
@Before
public void setUp() throws Exception {
NetconfOperationServiceFactoryListenerImpl factoriesListener = new NetconfOperationServiceFactoryListenerImpl();
factoriesListener.onAddNetconfOperationServiceFactory(new NetconfOperationServiceFactoryImpl(getYangStore()));
+ nettyThreadgroup = new NioEventLoopGroup();
+
commitNot = new DefaultCommitNotificationProducer(ManagementFactory.getPlatformMBeanServer());
dispatch = createDispatcher(Optional.<SSLContext> absent(), factoriesListener);
ChannelFuture s = dispatch.createServer(tcpAddress);
s.await();
+
+ clientDispatcher = new NetconfClientDispatcher(Optional.<SSLContext>absent(), nettyThreadgroup, nettyThreadgroup);
}
private NetconfServerDispatcher createDispatcher(Optional<SSLContext> sslC,
NetconfServerSessionListenerFactory listenerFactory = new NetconfServerSessionListenerFactory(
factoriesListener, commitNot, idProvider);
- return new NetconfServerDispatcher(sslC, serverNegotiatorFactory, listenerFactory);
+ NetconfServerDispatcher.ServerSslChannelInitializer serverChannelInitializer = new NetconfServerDispatcher.ServerSslChannelInitializer(
+ sslC, serverNegotiatorFactory, listenerFactory);
+ return new NetconfServerDispatcher(serverChannelInitializer, nettyThreadgroup, nettyThreadgroup);
}
@After
public void tearDown() throws Exception {
commitNot.close();
- dispatch.close();
- }
-
- @AfterClass
- public static void tearDownStatic() {
- NETCONF_CLIENT_DISPATCHER.close();
+ nettyThreadgroup.shutdownGracefully();
+ clientDispatcher.close();
}
private void loadMessages() throws IOException, SAXException, ParserConfigurationException {
@Test
public void testNetconfClientDemonstration() throws Exception {
- try (NetconfClient netconfClient = new NetconfClient("client", tcpAddress, 4000, NETCONF_CLIENT_DISPATCHER)) {
+ try (NetconfClient netconfClient = new NetconfClient("client", tcpAddress, 4000, clientDispatcher)) {
Set<String> capabilitiesFromNetconfServer = netconfClient.getCapabilities();
long sessionId = netconfClient.getSessionId();
@Test
public void testTwoSessions() throws Exception {
- try (NetconfClient netconfClient = new NetconfClient("1", tcpAddress, 4000, NETCONF_CLIENT_DISPATCHER)) {
- try (NetconfClient netconfClient2 = new NetconfClient("2", tcpAddress, 4000, NETCONF_CLIENT_DISPATCHER)) {
+ try (NetconfClient netconfClient = new NetconfClient("1", tcpAddress, 4000, clientDispatcher)) {
+ try (NetconfClient netconfClient2 = new NetconfClient("2", tcpAddress, 4000, clientDispatcher)) {
}
}
}
+ "<no-arg xmlns=\""
+ expectedNamespace
+ "\"> "
- + "<context-instance>/data/modules/module[name='impl-netconf']/instance[name='instance']</context-instance>"
+ + "<context-instance>/modules/module[type='impl-netconf'][name='instance']</context-instance>"
+ "<arg1>argument1</arg1>" + "</no-arg>" + "</rpc>";
final Document doc = XmlUtil.readXmlToDocument(rpc);
final NetconfMessage message = netconfClient.sendMessage(new NetconfMessage(doc));
// final InputStream resourceAsStream =
// AbstractListenerTest.class.getResourceAsStream(fileName);
// assertNotNull(resourceAsStream);
- try (NetconfClient netconfClient = new NetconfClient("test", tcpAddress, 5000, NETCONF_CLIENT_DISPATCHER)) {
+ try (NetconfClient netconfClient = new NetconfClient("test", tcpAddress, 5000, clientDispatcher)) {
// IOUtils.copy(resourceAsStream, netconfClient.getStream());
// netconfClient.getOutputStream().write(NetconfMessageFactory.endOfMessage);
// server should not write anything back
}
private NetconfClient createSession(final InetSocketAddress address, final String expected) throws Exception {
- final NetconfClient netconfClient = new NetconfClient("test " + address.toString(), address, 5000, NETCONF_CLIENT_DISPATCHER);
+ final NetconfClient netconfClient = new NetconfClient("test " + address.toString(), address, 5000, clientDispatcher);
assertEquals(expected, Long.toString(netconfClient.getSessionId()));
return netconfClient;
}