~ubuntu-branches/ubuntu/quantal/ehcache/quantal

« back to all changes in this revision

Viewing changes to src/test/java/net/sf/ehcache/terracotta/StorageStrategyInvalidConfigurationTest.java

  • Committer: Package Import Robot
  • Author(s): Miguel Landaeta
  • Date: 2012-03-01 19:15:46 UTC
  • mfrom: (1.1.6) (2.1.7 sid)
  • Revision ID: package-import@ubuntu.com-20120301191546-rvlk8tomip0c2m9p
Tags: 2.5.0-1
* Team upload.
* New upstream release. (Closes: #661450).
* Bump Standards-Version to 3.9.3. No changes were required.
* Fix lintian warning with copyright file.
* Remove unnecessary dependencies on JRE for libehcache-java.
* Wrap list of dependencies and uploaders.
* Fix clean target by adding a mh_clean call, to allow twice in a row builds.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/**
 
2
 *  Copyright 2003-2010 Terracotta, Inc.
 
3
 *
 
4
 *  Licensed under the Apache License, Version 2.0 (the "License");
 
5
 *  you may not use this file except in compliance with the License.
 
6
 *  You may obtain a copy of the License at
 
7
 *
 
8
 *      http://www.apache.org/licenses/LICENSE-2.0
 
9
 *
 
10
 *  Unless required by applicable law or agreed to in writing, software
 
11
 *  distributed under the License is distributed on an "AS IS" BASIS,
 
12
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 
13
 *  See the License for the specific language governing permissions and
 
14
 *  limitations under the License.
 
15
 */
 
16
 
 
17
package net.sf.ehcache.terracotta;
 
18
 
 
19
import static org.mockito.Mockito.mock;
 
20
import static org.mockito.Mockito.when;
 
21
 
 
22
import java.util.regex.Pattern;
 
23
 
 
24
import junit.framework.Assert;
 
25
import junit.framework.TestCase;
 
26
import net.sf.ehcache.CacheManager;
 
27
import net.sf.ehcache.cluster.CacheCluster;
 
28
import net.sf.ehcache.config.InvalidConfigurationException;
 
29
 
 
30
import org.junit.Test;
 
31
import org.junit.runner.RunWith;
 
32
import org.mockito.runners.MockitoJUnitRunner;
 
33
import org.slf4j.Logger;
 
34
import org.slf4j.LoggerFactory;
 
35
 
 
36
@RunWith(MockitoJUnitRunner.class)
 
37
public class StorageStrategyInvalidConfigurationTest extends TestCase {
 
38
 
 
39
    private static final Logger LOG = LoggerFactory.getLogger(StorageStrategyInvalidConfigurationTest.class);
 
40
 
 
41
    @Test
 
42
    public void testInvalidRejoinWithoutNonstop() throws Exception {
 
43
        ClusteredInstanceFactory mockFactory = mock(ClusteredInstanceFactory.class);
 
44
        TerracottaUnitTesting.setupTerracottaTesting(mockFactory);
 
45
 
 
46
        CacheCluster mockCacheCluster = new MockCacheCluster();
 
47
        when(mockFactory.getTopology()).thenReturn(mockCacheCluster);
 
48
 
 
49
        try {
 
50
            new CacheManager(CacheManager.class.getResourceAsStream("/ehcache-classic-with-nonstop-invalid-configuration-test.xml"));
 
51
            fail("Trying to run rejoin without nonstop terracotta caches should fail");
 
52
        } catch (InvalidConfigurationException e) {
 
53
            LOG.info("Caught expected exception: " + e);
 
54
 
 
55
            Assert.assertTrue(e.getMessage().contains("Cache 'cache1' error: NONSTOP can't be enabled with CLASSIC strategy."));
 
56
            Assert.assertTrue(e.getMessage().contains("Cache 'cache1' error: REJOIN can't be enabled with CLASSIC strategy."));
 
57
            Assert.assertTrue(e.getMessage().contains("Cache 'cache1' error: EVENTUAL consistency can't be enabled with CLASSIC strategy."));
 
58
 
 
59
            Assert.assertTrue(e.getMessage().contains("Cache 'cache2' error: NONSTOP can't be enabled with CLASSIC strategy."));
 
60
            Assert.assertTrue(e.getMessage().contains("Cache 'cache2' error: REJOIN can't be enabled with CLASSIC strategy."));
 
61
            Assert.assertTrue(e.getMessage().contains("Cache 'cache2' error: EVENTUAL consistency can't be enabled with CLASSIC strategy."));
 
62
 
 
63
            Assert.assertTrue(e.getMessage().contains("Cache 'cache3' error: REJOIN can't be enabled with CLASSIC strategy."));
 
64
            Assert.assertTrue(e.getMessage().contains("Cache 'cache3' error: EVENTUAL consistency can't be enabled with CLASSIC strategy."));
 
65
            Assert.assertTrue(e.getMessage().contains("Cache 'cache3' error: Terracotta clustered caches must be nonstop when rejoin is enabled."));
 
66
 
 
67
            Assert.assertEquals(12, Pattern.compile("$", Pattern.MULTILINE).split(e.getMessage()).length);
 
68
        }
 
69
    }
 
70
}