@Override
  protected void afterSitesCreated() {
    super.afterSitesCreated();

    ConfigurationBuilder builder = newConfiguration();
    builder.sites().addBackup().site(siteName(2)).strategy(BackupConfiguration.BackupStrategy.SYNC);
    defineInSite(site(0), CacheType.BACKUP_TO_SITE_2.name(), builder.build());
    defineInSite(site(2), CacheType.BACKUP_TO_SITE_2.name(), newConfiguration().build());

    builder = newConfiguration();
    builder.sites().addBackup().site(siteName(1)).strategy(BackupConfiguration.BackupStrategy.SYNC);
    builder.sites().addBackup().site(siteName(2)).strategy(BackupConfiguration.BackupStrategy.SYNC);
    defineInSite(site(0), CacheType.BACKUP_TO_SITE_1_AND_2.name(), builder.build());
    defineInSite(site(1), CacheType.BACKUP_TO_SITE_1_AND_2.name(), newConfiguration().build());
    defineInSite(site(2), CacheType.BACKUP_TO_SITE_1_AND_2.name(), newConfiguration().build());

    defineInSite(site(0), CacheType.NO_BACKUP.name(), newConfiguration().build());

    // wait for caches in primary cluster
    site(0).waitForClusterToForm(null);
    site(0).waitForClusterToForm(CacheType.BACKUP_TO_SITE_1_AND_2.name());
    site(0).waitForClusterToForm(CacheType.BACKUP_TO_SITE_1_AND_2.name());
    site(0).waitForClusterToForm(CacheType.BACKUP_TO_SITE_2.name());

    // wait for caches in backup site 1
    site(1).waitForClusterToForm(null);
    site(1).waitForClusterToForm(CacheType.BACKUP_TO_SITE_1_AND_2.name());

    // wait for caches in backup site 2
    site(2).waitForClusterToForm(CacheType.BACKUP_TO_SITE_1_AND_2.name());
    site(2).waitForClusterToForm(CacheType.BACKUP_TO_SITE_2.name());
  }
예제 #2
0
  @Override
  protected EmbeddedCacheManager createCacheManager() throws Exception {
    GlobalConfigurationBuilder lonGc = GlobalConfigurationBuilder.defaultClusteredBuilder();
    lonGc.site().localSite("LON");
    ConfigurationBuilder lon = getDefaultClusteredCacheConfig(CacheMode.LOCAL, false);
    lon.sites().addBackup().site("NYC").strategy(BackupConfiguration.BackupStrategy.SYNC);
    nycBackup = getDefaultClusteredCacheConfig(CacheMode.LOCAL, false);
    nycBackup.sites().backupFor().remoteSite("NYC").defaultRemoteCache();

    // Remember to not do nothing else other than
    // creating the cache manager in order to avoid leaks
    return TestCacheManagerFactory.createClusteredCacheManager(lonGc, lon);
  }
 public void testMultipleCachesWithNoCacheName() {
   ConfigurationBuilder cb = new ConfigurationBuilder();
   cb.sites()
       .addBackup()
       .site("LON")
       .strategy(BackupConfiguration.BackupStrategy.SYNC)
       .sites()
       .addBackup()
       .site("SFO")
       .sites()
       .addBackup()
       .site("NYC");
   cb.build();
 }
 @Override
 protected ConfigurationBuilder defaultConfigurationForSite(int siteIndex) {
   if (siteIndex == 0) {
     // default cache will backup to site_1
     ConfigurationBuilder builder = newConfiguration();
     builder
         .sites()
         .addBackup()
         .site(siteName(1))
         .strategy(BackupConfiguration.BackupStrategy.SYNC);
     return builder;
   } else {
     return newConfiguration();
   }
 }
 @Test(expectedExceptions = CacheConfigurationException.class)
 public void testSameBackupDefinedMultipleTimes() {
   ConfigurationBuilder cb = new ConfigurationBuilder();
   cb.sites()
       .addBackup()
       .site("LON")
       .strategy(BackupConfiguration.BackupStrategy.SYNC)
       .sites()
       .addBackup()
       .site("LON")
       .sites()
       .addBackup()
       .site("NYC");
   cb.build();
 }
  public void testApi() {
    ConfigurationBuilder cb = new ConfigurationBuilder();
    cb.sites()
        .addBackup()
        .site("LON")
        .strategy(BackupConfiguration.BackupStrategy.SYNC)
        .sites()
        .addBackup()
        .site("SFO")
        .sites()
        .addBackup()
        .site("NYC");
    assertEquals(cb.sites().backups().size(), 3);
    BackupConfigurationBuilder backup0 = cb.sites().backups().get(0);
    assertEquals(backup0.site(), "LON");
    assertEquals(backup0.strategy(), BackupConfiguration.BackupStrategy.SYNC);

    BackupConfigurationBuilder backup1 = cb.sites().backups().get(1);
    assertEquals(backup1.site(), "SFO");
    assertEquals(backup1.strategy(), BackupConfiguration.BackupStrategy.ASYNC);

    BackupConfigurationBuilder backup2 = cb.sites().backups().get(2);
    assertEquals(backup2.site(), "NYC");
    assertEquals(backup2.strategy(), BackupConfiguration.BackupStrategy.ASYNC);

    Configuration b = cb.build();
    assertEquals(b.sites().allBackups().size(), 3);
    BackupConfiguration b0 = b.sites().allBackups().get(0);
    assertEquals(b0.site(), "LON");
    assertEquals(b0.strategy(), BackupConfiguration.BackupStrategy.SYNC);

    BackupConfiguration b1 = b.sites().allBackups().get(1);
    assertEquals(b1.site(), "SFO");
    assertEquals(b1.strategy(), BackupConfiguration.BackupStrategy.ASYNC);

    BackupConfigurationBuilder b2 = cb.sites().backups().get(2);
    assertEquals(b2.site(), "NYC");
    assertEquals(b2.strategy(), BackupConfiguration.BackupStrategy.ASYNC);
  }