2
* Copyright 2003-2010 Terracotta, Inc.
2
* Copyright Terracotta, Inc.
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
21
21
import net.sf.ehcache.CacheException;
22
22
import net.sf.ehcache.CacheManager;
23
23
import net.sf.ehcache.config.CacheConfiguration;
24
import net.sf.ehcache.config.ConfigError;
25
import net.sf.ehcache.config.Configuration;
26
import net.sf.ehcache.config.ConfigurationFactory;
24
27
import net.sf.ehcache.config.NonstopConfiguration;
28
import net.sf.ehcache.config.TerracottaClientConfiguration;
25
29
import net.sf.ehcache.config.TerracottaConfiguration;
30
import net.sf.ehcache.config.generator.ConfigurationUtil;
31
import org.junit.Assert;
26
32
import org.slf4j.Logger;
27
33
import org.slf4j.LoggerFactory;
35
import java.io.BufferedInputStream;
36
import java.io.ByteArrayInputStream;
37
import java.util.Collection;
29
39
public class NonStopConfigTest extends TestCase {
31
41
private static final Logger LOG = LoggerFactory.getLogger(NonStopConfigTest.class);
72
82
assertEquals(timeoutBehavior, nonstopConfiguration.getTimeoutBehavior().getType());
86
public void testNonStopDefaultConfigWrites() {
88
NonstopConfiguration ns=new NonstopConfiguration().enabled(true);
90
TerracottaConfiguration tcConf = new TerracottaConfiguration().clustered(true).coherent(true).consistency
91
(TerracottaConfiguration.Consistency.STRONG);
92
tcConf.getNonstopConfiguration().enabled(true).timeoutMillis(10000);
94
TerracottaConfiguration tcConf2 = new TerracottaConfiguration().clustered(true).coherent(true).consistency
95
(TerracottaConfiguration.Consistency.STRONG);
96
tcConf2.getNonstopConfiguration().enabled(false).timeoutMillis(10000);
98
// now, these two condifgs should be different, with only the first being enabled.
100
Assert.assertTrue(tcConf.getNonstopConfiguration().isEnabled()!= tcConf2.getNonstopConfiguration()
103
// now, send it full trip
104
CacheConfiguration cconf=new CacheConfiguration().name("foo").terracotta(tcConf);
105
Configuration conf=new Configuration().cache(cconf);
106
conf.terracotta(new TerracottaClientConfiguration().url("localhost","10000").rejoin(true));
107
String asText= ConfigurationUtil.generateCacheManagerConfigurationText(conf);
109
Assert.assertTrue(asText.contains("nonstop"));
111
// finally parse it back in, make sure it all hangs together.
112
Configuration parsedConfig = ConfigurationFactory
113
.parseConfiguration(new BufferedInputStream(new ByteArrayInputStream(asText.getBytes())));
115
Assert.assertTrue(parsedConfig.getCacheConfigurations().get("foo").getTerracottaConfiguration().getNonstopConfiguration().isEnabled());
118
Collection<ConfigError> errors = parsedConfig.validate();
119
Assert.assertEquals(errors.size(),0);