All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.infinispan.server.test.junit4.InfinispanXSiteServerRuleBuilder Maven / Gradle / Ivy

package org.infinispan.server.test.junit4;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;

import org.infinispan.server.test.core.TestServer;

/**
 * Builder for {@link InfinispanXSiteServerRule}.
 *
 * @author Gustavo Lira <[email protected]>
 * @since 12.0
 */

public class InfinispanXSiteServerRuleBuilder {

   private final List sites = new ArrayList<>();

   public InfinispanXSiteServerRuleBuilder addSite(String siteName, InfinispanServerRuleBuilder siteBuilder) {
      siteBuilder.site(siteName);
      sites.add(siteBuilder);
      return this;
   }

   public InfinispanXSiteServerRule build() {
      Set uniqueSiteName = new HashSet<>();
      List sitesTestServers = sites.stream()
            .map(InfinispanServerRuleBuilder::build)
            .map(InfinispanServerRule::getTestServer)
            .peek(testServer -> {
               if (!uniqueSiteName.add(testServer.getSiteName())) {
                  throw new IllegalStateException("Site name already set: " + testServer.getSiteName());
               }
            })
            .collect(Collectors.toList());
      return new InfinispanXSiteServerRule(sitesTestServers);
   }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy