ServerConnectionFactory { ServerConnection makeServerConnection(final Socket socket, final InternalCache cache, final CachedRegionHelper cachedRegionHelper, final CacheServerStats stats, final int hsTimeout, final int socketBufferSize, final String communicationModeStr, final byte communicationMode, final Acceptor acceptor, final SecurityService securityService) throws IOException { if (ProtobufClientServerProtocol.getModeNumber() == communicationMode) { if (!Boolean.getBoolean("geode.feature-protobuf-protocol")) { throw new IOException("Server received unknown communication mode: " + communicationMode); } try { return createProtobufServerConnection(socket, cache, cachedRegionHelper, stats, hsTimeout, socketBufferSize, communicationModeStr, communicationMode, acceptor, securityService); } catch (ServiceLoadingFailureException ex) { throw new IOException("Could not load protobuf client protocol", ex); } catch (ServiceVersionNotFoundException ex) { throw new IOException("No service matching provided version byte", ex); } } return new OriginalServerConnection(socket, cache, cachedRegionHelper, stats, hsTimeout, socketBufferSize, communicationModeStr, communicationMode, acceptor, securityService); } ServerConnectionFactory();   }
@Test public void newClientProtocolFailsWithoutSystemPropertySet() { Throwable thrown = catchThrowable( () -> new ServerConnectionFactory().makeServerConnection(mock(Socket.class), mock(InternalCache.class), mock(CachedRegionHelper.class), mock(CacheServerStats.class), 0, 0, "", CommunicationMode.ProtobufClientServerProtocol.getModeNumber(), mock(AcceptorImpl.class), mock(SecurityService.class))); assertThat(thrown).isInstanceOf(IOException.class); }
@Test public void newClientProtocolFailsWithSystemPropertySet() { System.setProperty("geode.feature-protobuf-protocol", "true"); Throwable thrown = catchThrowable( () -> new ServerConnectionFactory().makeServerConnection(mock(Socket.class), mock(InternalCache.class), mock(CachedRegionHelper.class), mock(CacheServerStats.class), 0, 0, "", CommunicationMode.ProtobufClientServerProtocol.getModeNumber(), mock(AcceptorImpl.class), mock(SecurityService.class))); assertThat(thrown).hasRootCauseInstanceOf(ServiceLoadingFailureException.class); }
@Test @Parameters({"ClientToServer", "PrimaryServerToClient", "SecondaryServerToClient", "GatewayToGateway", "MonitorToServer", "SuccessfulServerToClient", "UnsuccessfulServerToClient", "ClientToServer"}) @TestCaseName("{method}({params})") public void makeServerConnection(CommunicationMode communicationMode) throws Exception { Socket socket = mock(Socket.class); when(socket.getInetAddress()).thenReturn(InetAddress.getByName("localhost")); when(socket.getInputStream()).thenReturn(mock(InputStream.class)); ServerConnection serverConnection = new ServerConnectionFactory().makeServerConnection(socket, mock(InternalCache.class), mock(CachedRegionHelper.class), mock(CacheServerStats.class), 0, 0, "", communicationMode.getModeNumber(), mock(AcceptorImpl.class), mock(SecurityService.class)); assertThat(serverConnection).isInstanceOf(OriginalServerConnection.class); }
@Test @Parameters({"ClientToServer", "PrimaryServerToClient", "SecondaryServerToClient", "GatewayToGateway", "MonitorToServer", "SuccessfulServerToClient", "UnsuccessfulServerToClient", "ClientToServer"}) @TestCaseName("{method}({params})") public void makeServerConnectionForOldProtocolWithFeatureFlagEnabled( CommunicationMode communicationMode) throws IOException { System.setProperty("geode.feature-protobuf-protocol", "true"); Socket socket = mock(Socket.class); when(socket.getInetAddress()).thenReturn(InetAddress.getByName("localhost")); when(socket.getInputStream()).thenReturn(mock(InputStream.class)); ServerConnection serverConnection = new ServerConnectionFactory().makeServerConnection(socket, mock(InternalCache.class), mock(CachedRegionHelper.class), mock(CacheServerStats.class), 0, 0, "", communicationMode.getModeNumber(), mock(AcceptorImpl.class), mock(SecurityService.class)); assertThat(serverConnection).isInstanceOf(OriginalServerConnection.class); }