BAEL-4904: Keep the strong reference to the MessengerService (#10602)

Co-authored-by: Krzysztof Woyke <krzysztof.woyke.sp@lhsystems.com>
This commit is contained in:
kwoyke 2021-03-28 15:26:28 +02:00 committed by GitHub
parent 51bc24aa53
commit b7cbb5428d
1 changed files with 31 additions and 31 deletions

View File

@ -1,24 +1,25 @@
package com.baeldung.rmi; package com.baeldung.rmi;
import static org.junit.Assert.assertEquals; import org.junit.Before;
import static org.junit.Assert.fail; import org.junit.Test;
import java.rmi.NotBoundException; import java.rmi.NotBoundException;
import java.rmi.RemoteException; import java.rmi.RemoteException;
import java.rmi.registry.LocateRegistry; import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry; import java.rmi.registry.Registry;
import org.junit.BeforeClass; import static org.junit.Assert.assertEquals;
import org.junit.Test; import static org.junit.Assert.fail;
public class JavaRMIIntegrationTest { public class JavaRMIIntegrationTest {
@BeforeClass private MessengerServiceImpl messengerService;
public static void whenRunServer_thenServerStarts() {
@Before
public void init() {
try { try {
MessengerServiceImpl server = new MessengerServiceImpl(); messengerService = new MessengerServiceImpl();
server.createStubAndBind(); messengerService.createStubAndBind();
} catch (RemoteException e) { } catch (RemoteException e) {
fail("Exception Occurred: " + e); fail("Exception Occurred: " + e);
} }
@ -26,7 +27,6 @@ public class JavaRMIIntegrationTest {
@Test @Test
public void whenClientSendsMessageToServer_thenServerSendsResponseMessage() { public void whenClientSendsMessageToServer_thenServerSendsResponseMessage() {
try { try {
Registry registry = LocateRegistry.getRegistry(); Registry registry = LocateRegistry.getRegistry();
MessengerService server = (MessengerService) registry.lookup("MessengerService"); MessengerService server = (MessengerService) registry.lookup("MessengerService");
@ -36,7 +36,7 @@ public class JavaRMIIntegrationTest {
assertEquals(responseMessage, expectedMessage); assertEquals(responseMessage, expectedMessage);
} catch (RemoteException | NotBoundException e) { } catch (RemoteException | NotBoundException e) {
fail("Exception Occurred: " + e); fail("Exception Occurred: " + e);
}; }
} }
} }