Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

true
Info
Please keep in mind that so much of this is just boiler plate to connect all the dots. The serialization support, in particular, is super picky.
Page properties
hidden


Here is the unit test of this code


public class BlogCodeDUnitTest {

@Rule
public ClusterStartupRule cluster = new ClusterStartupRule();

private MemberVM locator;
private List<MemberVM> servers;
private static final int SERVERS_TO_START = 1;

private ClusterManagementService client1;

@Before
public void setup() {
     locator = cluster.startLocatorVM(0, MemberStarterRule::withHttpService);
     servers = new ArrayList<>();
     int locatorPort = locator.getPort();
     IntStream.range(0, SERVERS_TO_START)
       .forEach(i -> servers.add(cluster.startServerVM(i + 1, locatorPort)));

    client1 = new ClusterManagementServiceBuilder()
      .setHost("localhost")
      .setPort(locator.getHttpPort())
      .build();
  }

@After
public void tearDown() {
    client1.close();
  }

@Test
public void testBlogCode() throws ExecutionException, InterruptedException {

    BlogCodeRequest blogCodeRequest = new BlogCodeRequest();

    ClusterManagementOperationResult<BlogCodeRequest, BlogCodeResponse> startResult =
    client1.start(blogCodeRequest);

    assertThat(startResult.isSuccessful()).isTrue();

    ClusterManagementOperationResult<BlogCodeRequest, BlogCodeResponse> endResult =
    client1.getFuture(blogCodeRequest, startResult.getOperationId()).get();

    BlogCodeResponse blogCodeResponse = endResult.getOperationResult();

    assertThat(blogCodeResponse.getSuccess()).isTrue();

    assertThat(blogCodeResponse.getStatusMessage()).isEqualTo("Hello, World!");
  }

}