~ubuntu-branches/ubuntu/trusty/ehcache/trusty

« back to all changes in this revision

Viewing changes to src/test/java/net/sf/ehcache/config/nonstop/NonStopConfigTest.java

  • Committer: Package Import Robot
  • Author(s): Emmanuel Bourg
  • Date: 2013-05-06 14:53:07 UTC
  • mfrom: (1.1.7) (2.1.8 sid)
  • Revision ID: package-import@ubuntu.com-20130506145307-v5bhw5yu70re00l3
Tags: 2.6.7-1
* Team upload.
* New upstream release

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/**
2
 
 *  Copyright 2003-2010 Terracotta, Inc.
 
2
 *  Copyright Terracotta, Inc.
3
3
 *
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;
28
34
 
 
35
import java.io.BufferedInputStream;
 
36
import java.io.ByteArrayInputStream;
 
37
import java.util.Collection;
 
38
 
29
39
public class NonStopConfigTest extends TestCase {
30
40
 
31
41
    private static final Logger LOG = LoggerFactory.getLogger(NonStopConfigTest.class);
72
82
        assertEquals(timeoutBehavior, nonstopConfiguration.getTimeoutBehavior().getType());
73
83
    }
74
84
 
 
85
 
 
86
    public void testNonStopDefaultConfigWrites() {
 
87
        // DEV-8234
 
88
        NonstopConfiguration ns=new NonstopConfiguration().enabled(true);
 
89
 
 
90
        TerracottaConfiguration tcConf = new TerracottaConfiguration().clustered(true).coherent(true).consistency
 
91
                (TerracottaConfiguration.Consistency.STRONG);
 
92
        tcConf.getNonstopConfiguration().enabled(true).timeoutMillis(10000);
 
93
 
 
94
        TerracottaConfiguration tcConf2 = new TerracottaConfiguration().clustered(true).coherent(true).consistency
 
95
                (TerracottaConfiguration.Consistency.STRONG);
 
96
        tcConf2.getNonstopConfiguration().enabled(false).timeoutMillis(10000);
 
97
 
 
98
        // now, these two condifgs should be different, with only the first being enabled.
 
99
 
 
100
        Assert.assertTrue(tcConf.getNonstopConfiguration().isEnabled()!= tcConf2.getNonstopConfiguration()
 
101
                .isEnabled());
 
102
 
 
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);
 
108
 
 
109
        Assert.assertTrue(asText.contains("nonstop"));
 
110
 
 
111
        // finally parse it back in, make sure it all hangs together.
 
112
        Configuration parsedConfig = ConfigurationFactory
 
113
                .parseConfiguration(new BufferedInputStream(new ByteArrayInputStream(asText.getBytes())));
 
114
 
 
115
        Assert.assertTrue(parsedConfig.getCacheConfigurations().get("foo").getTerracottaConfiguration().getNonstopConfiguration().isEnabled());
 
116
 
 
117
        // no errors
 
118
        Collection<ConfigError> errors = parsedConfig.validate();
 
119
        Assert.assertEquals(errors.size(),0);
 
120
 
 
121
    }
 
122
 
75
123
}