GatewayReceiverFactoryImpl implements GatewayReceiverFactory { @Override public GatewayReceiver create() { if (this.startPort > this.endPort) { throw new IllegalStateException( "Please specify either start port a value which is less than end port."); } if ((this.cache.getGatewayReceivers() != null) && (!this.cache.getGatewayReceivers().isEmpty())) { throw new IllegalStateException(A_GATEWAY_RECEIVER_ALREADY_EXISTS_ON_THIS_MEMBER); } GatewayReceiver recv = null; if (this.cache instanceof GemFireCacheImpl) { recv = new GatewayReceiverImpl(cache, this.startPort, this.endPort, this.timeBetPings, this.socketBuffSize, this.bindAdd, this.filters, this.hostnameForSenders, this.manualStart); this.cache.addGatewayReceiver(recv); InternalDistributedSystem system = (InternalDistributedSystem) this.cache.getDistributedSystem(); system.handleResourceEvent(ResourceEvent.GATEWAYRECEIVER_CREATE, recv); if (!this.manualStart) { try { recv.start(); } catch (IOException ioe) { throw new GatewayReceiverException( "Exception occurred while starting gateway receiver", ioe); } } } else if (this.cache instanceof CacheCreation) { recv = new GatewayReceiverCreation(this.cache, this.startPort, this.endPort, this.timeBetPings, this.socketBuffSize, this.bindAdd, this.filters, this.hostnameForSenders, this.manualStart); this.cache.addGatewayReceiver(recv); } return recv; } GatewayReceiverFactoryImpl();  GatewayReceiverFactoryImpl(InternalCache cache); @Override GatewayReceiverFactory addGatewayTransportFilter(GatewayTransportFilter filter); @Override GatewayReceiverFactory removeGatewayTransportFilter(GatewayTransportFilter filter); @Override GatewayReceiverFactory setMaximumTimeBetweenPings(int time); @Override GatewayReceiverFactory setStartPort(int port); @Override GatewayReceiverFactory setEndPort(int port); @Override GatewayReceiverFactory setSocketBufferSize(int size); @Override GatewayReceiverFactory setBindAddress(String address); @Override GatewayReceiverFactory setHostnameForSenders(String address); @Override GatewayReceiverFactory setManualStart(boolean start); @Override GatewayReceiver create();  }
@Test public void createDoesNotUseManualStartByDefault() { GatewayReceiver receiver = gatewayReceiverFactory.create(); assertThat(receiver.isManualStart()).isFalse(); }
@Test public void createDoesNotUseGatewayTransportFiltersByDefault() { GatewayReceiver receiver = gatewayReceiverFactory.create(); assertThat(receiver.getGatewayTransportFilters()).isEmpty(); }
@Test public void createUsesEndPortDefault() { int endPortDefault = 5500; GatewayReceiver receiver = gatewayReceiverFactory.create(); assertThat(receiver.getEndPort()).isEqualTo(endPortDefault); }
@Test public void createUsesStartPortDefault() { int startPortDefault = 5000; GatewayReceiver receiver = gatewayReceiverFactory.create(); assertThat(receiver.getStartPort()).isEqualTo(startPortDefault); }
@Test public void createUsesBindAddressDefault() { GatewayReceiver receiver = gatewayReceiverFactory.create(); assertThat(receiver.getBindAddress()).isEqualTo(""); }
@Test public void createUsesSocketBufferSizeDefault() { String socketBufferSizeDefault = "524288"; GatewayReceiver receiver = gatewayReceiverFactory.create(); assertThat(receiver.getSocketBufferSize()).isEqualTo(Integer.valueOf(socketBufferSizeDefault)); }
@Test public void createUsesHostnameForSendersDefault() { GatewayReceiver receiver = gatewayReceiverFactory.create(); assertThat(receiver.getHostnameForSenders()).isEqualTo(""); }
@Test public void createUsesMaximumTimeBetweenPingsDefault() { int maximumTimeBetweenPingsDefault = 60000; GatewayReceiver receiver = gatewayReceiverFactory.create(); assertThat(receiver.getMaximumTimeBetweenPings()).isEqualTo(maximumTimeBetweenPingsDefault); }
@Test public void createAddsGatewayReceiverToCache() { GatewayReceiver receiver = gatewayReceiverFactory.create(); verify(cache).addGatewayReceiver(receiver); }
@Test public void createThrowsIllegalStateExceptionIfGatewayReceiverAlreadyExists() { when(cache.getGatewayReceivers()).thenReturn(singleton(mock(GatewayReceiver.class))); Throwable thrown = catchThrowable(() -> gatewayReceiverFactory.create()); assertThat(thrown).isInstanceOf(IllegalStateException.class); }