2
* Copyright 2003-2010 Terracotta, Inc.
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
8
* http://www.apache.org/licenses/LICENSE-2.0
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.
17
package net.sf.ehcache.terracotta;
19
import static org.mockito.Mockito.mock;
20
import static org.mockito.Mockito.when;
22
import java.util.regex.Pattern;
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;
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;
36
@RunWith(MockitoJUnitRunner.class)
37
public class StorageStrategyInvalidConfigurationTest extends TestCase {
39
private static final Logger LOG = LoggerFactory.getLogger(StorageStrategyInvalidConfigurationTest.class);
42
public void testInvalidRejoinWithoutNonstop() throws Exception {
43
ClusteredInstanceFactory mockFactory = mock(ClusteredInstanceFactory.class);
44
TerracottaUnitTesting.setupTerracottaTesting(mockFactory);
46
CacheCluster mockCacheCluster = new MockCacheCluster();
47
when(mockFactory.getTopology()).thenReturn(mockCacheCluster);
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);
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."));
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."));
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."));
67
Assert.assertEquals(12, Pattern.compile("$", Pattern.MULTILINE).split(e.getMessage()).length);