* terms of the Eclipse Public License v1.0 which accompanies this distribution,
* and is available at http://www.eclipse.org/legal/epl-v10.html
*/
-
-
package org.opendaylight.openflowjava.protocol.impl.core;
import com.google.common.util.concurrent.ListenableFuture;
-
/**
* Shutdown provider interface.
*
*/
public interface ShutdownProvider {
- ListenableFuture<Boolean> shutdown();
+ ListenableFuture<Void> shutdown();
}
}
@Override
- public ListenableFuture<Boolean> shutdown() {
+ public ListenableFuture<Void> shutdown() {
LOG.debug("Shutdown summoned");
if (serverFacade == null) {
LOG.warn("Can not shutdown - not configured or started");
throw new IllegalStateException("SwitchConnectionProvider is not started or not configured.");
}
- ListenableFuture<Boolean> serverFacadeShutdownFuture = serverFacade.shutdown();
+ final var serverFacadeShutdownFuture = serverFacade.shutdown();
Executors.shutdownAndAwaitTermination(listeningExecutorService);
return serverFacadeShutdownFuture;
}
* Shuts down {@link TcpHandler}}.
*/
@Override
- public ListenableFuture<Boolean> shutdown() {
- final SettableFuture<Boolean> result = SettableFuture.create();
+ public ListenableFuture<Void> shutdown() {
+ final var result = SettableFuture.<Void>create();
workerGroup.shutdownGracefully();
// boss will shutdown as soon, as worker is down
bossGroup.shutdownGracefully().addListener(downResult -> {
- result.set(downResult.isSuccess());
- if (downResult.cause() != null) {
- result.setException(downResult.cause());
+ final var cause = downResult.cause();
+ if (cause != null) {
+ result.setException(cause);
+ } else {
+ result.set(null);
}
});
return result;
}
@Override
- public ListenableFuture<Boolean> shutdown() {
- final SettableFuture<Boolean> result = SettableFuture.create();
+ public ListenableFuture<Void> shutdown() {
+ final var result = SettableFuture.<Void>create();
group.shutdownGracefully().addListener(downResult -> {
- result.set(downResult.isSuccess());
- if (downResult.cause() != null) {
- result.setException(downResult.cause());
+ final var cause = downResult.cause();
+ if (cause != null) {
+ result.setException(cause);
+ } else {
+ result.set(null);
}
});
return result;
* terms of the Eclipse Public License v1.0 which accompanies this distribution,
* and is available at http://www.eclipse.org/legal/epl-v10.html
*/
-
package org.opendaylight.openflowjava.protocol.impl.core;
import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNull;
import static org.junit.Assert.fail;
-import com.google.common.util.concurrent.ListenableFuture;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.unix.Errors;
import java.io.IOException;
*/
@RunWith(MockitoJUnitRunner.class)
public class TcpHandlerTest {
+ private final InetAddress serverAddress = InetAddress.getLoopbackAddress();
- private final InetAddress serverAddress = InetAddress.getLoopbackAddress() ;
- @Mock ChannelHandlerContext mockChHndlrCtx ;
- @Mock TcpChannelInitializer mockChannelInitializer;
- @Mock SwitchConnectionHandler mockSwitchConnHndler ;
- @Mock SerializationFactory mockSerializationFactory ;
- @Mock DeserializationFactory mockDeserializationFactory ;
+ @Mock
+ ChannelHandlerContext mockChHndlrCtx;
+ @Mock
+ TcpChannelInitializer mockChannelInitializer;
+ @Mock
+ SwitchConnectionHandler mockSwitchConnHndler;
+ @Mock
+ SerializationFactory mockSerializationFactory;
+ @Mock
+ DeserializationFactory mockDeserializationFactory;
- TcpHandler tcpHandler ;
+ TcpHandler tcpHandler;
/**
* Test run with null address set.
* Trigger the server shutdown and wait 2 seconds for completion.
*/
private void shutdownServer() throws InterruptedException, ExecutionException {
- ListenableFuture<Boolean> shutdownRet = tcpHandler.shutdown() ;
- while (shutdownRet.isDone() != true) {
- Thread.sleep(100) ;
- }
- assertEquals("shutdown failed", true, shutdownRet.get());
+ final var shutdownRet = tcpHandler.shutdown() ;
+ assertNull(shutdownRet.get());
}
private Boolean startupServer(final boolean isEpollEnabled) throws InterruptedException {
import static org.hamcrest.CoreMatchers.instanceOf;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertThrows;
-import static org.junit.Assert.assertTrue;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.mock;
public void testShutdown() throws Exception {
startUp(TransportProtocol.TCP);
provider.startup(handler).get(WAIT_TIMEOUT, TimeUnit.MILLISECONDS);
- assertTrue("Failed to stop", provider.shutdown().get(5 * WAIT_TIMEOUT, TimeUnit.MILLISECONDS));
+ assertNull("Failed to stop", provider.shutdown().get(5 * WAIT_TIMEOUT, TimeUnit.MILLISECONDS));
}
}
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import java.net.InetAddress;
private void shutdownServer() throws InterruptedException, ExecutionException, TimeoutException {
final var shutdownRet = udpHandler.shutdown() ;
- assertTrue("Wrong - shutdown failed", shutdownRet.get(10, TimeUnit.SECONDS));
+ assertNull("Wrong - shutdown failed", shutdownRet.get(10, TimeUnit.SECONDS));
}
}
/**
* Stop listening to switches.
*
- * @return future, triggered to true, when all listening channels are down
+ * @return future completing when all channels are down
*/
- ListenableFuture<Boolean> shutdown();
+ ListenableFuture<Void> shutdown();
}
return fullyStarted;
}
- private ListenableFuture<List<Boolean>> shutdownSwitchConnections() {
- final ListenableFuture<List<Boolean>> listListenableFuture =
- Futures.allAsList(switchConnectionProviders.stream().map(switchConnectionProvider -> {
- // Revert deserializers to their original state
- if (config.getUseSingleLayerSerialization()) {
- DeserializerInjector.revertDeserializers(switchConnectionProvider);
- }
-
- // Shutdown switch connection provider
- return switchConnectionProvider.shutdown();
- }).collect(Collectors.toSet()));
-
- Futures.addCallback(listListenableFuture, new FutureCallback<List<Boolean>>() {
+ private ListenableFuture<List<Void>> shutdownSwitchConnections() {
+ final var listListenableFuture = Futures.allAsList(switchConnectionProviders.stream()
+ .map(switchConnectionProvider -> {
+ // Revert deserializers to their original state
+ if (config.getUseSingleLayerSerialization()) {
+ DeserializerInjector.revertDeserializers(switchConnectionProvider);
+ }
+
+ // Shutdown switch connection provider
+ return switchConnectionProvider.shutdown();
+ }).collect(Collectors.toList()));
+
+ Futures.addCallback(listListenableFuture, new FutureCallback<>() {
@Override
- public void onSuccess(final List<Boolean> result) {
+ public void onSuccess(final List<Void> result) {
LOG.info("All switchConnectionProviders were successfully shut down ({}).", result.size());
}
when(dataBroker.newWriteOnlyTransaction()).thenReturn(writeTransaction);
doReturn(CommitInfo.emptyFluentFuture()).when(writeTransaction).commit();
when(entityOwnershipService.registerListener(any(), any())).thenReturn(entityOwnershipListenerRegistration);
- when(switchConnectionProvider.startup(any())).thenReturn(Futures.immediateFuture(null));
- when(switchConnectionProvider.shutdown()).thenReturn(Futures.immediateFuture(true));
+ when(switchConnectionProvider.startup(any())).thenReturn(Futures.immediateVoidFuture());
+ when(switchConnectionProvider.shutdown()).thenReturn(Futures.immediateVoidFuture());
when(configurationService.getProperty(eq(ConfigurationProperty.USE_SINGLE_LAYER_SERIALIZATION.toString()),
any())).thenReturn(USE_SINGLE_LAYER_SERIALIZATION);
when(configurationService.getProperty(eq(ConfigurationProperty.THREAD_POOL_MIN_THREADS.toString()), any()))