|
| 1 | +/* |
| 2 | + * Copyright 2016-2019 the original author or authors. |
| 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 | + * https://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 | + |
| 18 | +package org.springframework.data.gemfire.config.annotation; |
| 19 | + |
| 20 | +import org.apache.geode.cache.EntryEvent; |
| 21 | +import org.apache.geode.cache.GemFireCache; |
| 22 | +import org.apache.geode.cache.RegionEvent; |
| 23 | +import org.springframework.context.annotation.Bean; |
| 24 | +import org.springframework.context.annotation.Configuration; |
| 25 | +import org.springframework.data.gemfire.ReplicatedRegionFactoryBean; |
| 26 | +import org.springframework.data.gemfire.eventing.config.EnableEventProcessing; |
| 27 | +import org.springframework.data.gemfire.eventing.config.RegionCacheListenerEventType; |
| 28 | + |
| 29 | +/** |
| 30 | + * Tests for {@link AsCacheListener} configured for a |
| 31 | + * {@link org.apache.geode.cache.server.CacheServer} |
| 32 | + * |
| 33 | + * @author Udo Kohlmeyer |
| 34 | + * @see org.junit.Test |
| 35 | + * @see org.mockito.Mockito |
| 36 | + * @see org.apache.geode.cache.server.CacheServer |
| 37 | + * @see Configuration |
| 38 | + * @see org.springframework.test.context.ContextConfiguration |
| 39 | + * @see org.springframework.test.context.junit4.SpringRunner |
| 40 | + * @since 2.3.0 |
| 41 | + */ |
| 42 | +public class AsRegionEventCacheServerConfigurationTests extends AsRegionEventConfigurationTests { |
| 43 | + |
| 44 | + protected static ReplicatedRegionFactoryBean<String, String> createRegionFactoryBean(GemFireCache cache, |
| 45 | + String regionName) { |
| 46 | + ReplicatedRegionFactoryBean<String, String> replicateRegion = new ReplicatedRegionFactoryBean<>(); |
| 47 | + replicateRegion.setName(regionName); |
| 48 | + replicateRegion.setCache(cache); |
| 49 | + return replicateRegion; |
| 50 | + } |
| 51 | + |
| 52 | + @Override protected Class<?> getRegionEventWithIncorrectRegionEventParameterConfiguration() { |
| 53 | + return TestConfigurationWithIncorrectRegionEventParameter.class; |
| 54 | + } |
| 55 | + |
| 56 | + @Override protected Class getCacheListenerAnnotationRegionEventClearConfiguration() { |
| 57 | + return TestConfigurationForRegionClear.class; |
| 58 | + } |
| 59 | + |
| 60 | + @Override protected Class getCacheListenerAnnotationWithInvalidRegion() { |
| 61 | + return TestConfigurationWithInvalidRegionNameConfiguration.class; |
| 62 | + } |
| 63 | + |
| 64 | + @Override protected Class getCacheListenerAnnotationRegionEventDestroyConfiguration() { |
| 65 | + return TestConfigurationForRegionDestroy.class; |
| 66 | + } |
| 67 | + |
| 68 | + @Override protected Class getCacheListenerAnnotationRegionEventInvalidateConfiguration() { |
| 69 | + return TestConfigurationForRegionInvalidate.class; |
| 70 | + } |
| 71 | + |
| 72 | + @Configuration @CacheServerApplication @EnableEventProcessing |
| 73 | + public static class TestConfigurationWithIncorrectRegionEventParameter { |
| 74 | + |
| 75 | + @Bean("TestRegion1") ReplicatedRegionFactoryBean getTestRegion(GemFireCache cache) { |
| 76 | + return createRegionFactoryBean(cache, "TestRegion1"); |
| 77 | + } |
| 78 | + |
| 79 | + @AsRegionEventListener(regionEventTypes = RegionCacheListenerEventType.AFTER_REGION_CREATE) |
| 80 | + public void afterCreateListener(EntryEvent event) { |
| 81 | + } |
| 82 | + } |
| 83 | + |
| 84 | + @Configuration @CacheServerApplication @EnableEventProcessing |
| 85 | + public static class TestConfigurationForRegionClear { |
| 86 | + |
| 87 | + @Bean("TestRegion1") ReplicatedRegionFactoryBean getTestRegion(GemFireCache cache) { |
| 88 | + return createRegionFactoryBean(cache, "TestRegion1"); |
| 89 | + } |
| 90 | + |
| 91 | + @AsRegionEventListener(regionEventTypes = RegionCacheListenerEventType.AFTER_REGION_CLEAR) |
| 92 | + public void afterCreateListener(RegionEvent event) { |
| 93 | + recordEvent(event); |
| 94 | + } |
| 95 | + } |
| 96 | + |
| 97 | + @Configuration @CacheServerApplication @EnableEventProcessing |
| 98 | + public static class TestConfigurationWithInvalidRegionNameConfiguration { |
| 99 | + |
| 100 | + @Bean("TestRegion1") ReplicatedRegionFactoryBean getTestRegion(GemFireCache cache) { |
| 101 | + return createRegionFactoryBean(cache, "TestRegion1"); |
| 102 | + } |
| 103 | + |
| 104 | + @AsRegionEventListener(regions = "TestRegion2", regionEventTypes = RegionCacheListenerEventType.ALL) |
| 105 | + public void afterCreateListener(RegionEvent event) { |
| 106 | + recordEvent(event); |
| 107 | + } |
| 108 | + } |
| 109 | + |
| 110 | + @Configuration @CacheServerApplication @EnableEventProcessing |
| 111 | + public static class TestConfigurationForRegionCreate { |
| 112 | + |
| 113 | + @Bean("TestRegion1") ReplicatedRegionFactoryBean getTestRegion(GemFireCache cache) { |
| 114 | + return createRegionFactoryBean(cache, "TestRegion1"); |
| 115 | + } |
| 116 | + |
| 117 | + @AsRegionEventListener(regionEventTypes = RegionCacheListenerEventType.AFTER_REGION_CREATE) |
| 118 | + public void afterCreateListener(RegionEvent event) { |
| 119 | + recordEvent(event); |
| 120 | + } |
| 121 | + } |
| 122 | + |
| 123 | + @Configuration @CacheServerApplication @EnableEventProcessing |
| 124 | + public static class TestConfigurationForRegionInvalidate { |
| 125 | + |
| 126 | + @Bean("TestRegion1") ReplicatedRegionFactoryBean getTestRegion(GemFireCache cache) { |
| 127 | + return createRegionFactoryBean(cache, "TestRegion1"); |
| 128 | + } |
| 129 | + |
| 130 | + @AsRegionEventListener(regionEventTypes = RegionCacheListenerEventType.AFTER_REGION_INVALIDATE) |
| 131 | + public void afterCreateListener(RegionEvent event) { |
| 132 | + recordEvent(event); |
| 133 | + } |
| 134 | + } |
| 135 | + |
| 136 | + @Configuration @CacheServerApplication @EnableEventProcessing |
| 137 | + public static class TestConfigurationForRegionDestroy { |
| 138 | + |
| 139 | + @Bean("TestRegion1") ReplicatedRegionFactoryBean getTestRegion(GemFireCache cache) { |
| 140 | + return createRegionFactoryBean(cache, "TestRegion1"); |
| 141 | + } |
| 142 | + |
| 143 | + @AsRegionEventListener(regionEventTypes = RegionCacheListenerEventType.AFTER_REGION_DESTROY) |
| 144 | + public void afterCreateListener(RegionEvent event) { |
| 145 | + recordEvent(event); |
| 146 | + } |
| 147 | + } |
| 148 | + |
| 149 | + @Configuration @CacheServerApplication @EnableEventProcessing |
| 150 | + public static class TestConfigurationForRegionLive { |
| 151 | + |
| 152 | + @Bean("TestRegion1") ReplicatedRegionFactoryBean getTestRegion(GemFireCache cache) { |
| 153 | + return createRegionFactoryBean(cache, "TestRegion1"); |
| 154 | + } |
| 155 | + |
| 156 | + @AsRegionEventListener(regionEventTypes = RegionCacheListenerEventType.AFTER_REGION_LIVE) |
| 157 | + public void afterCreateListener(RegionEvent event) { |
| 158 | + recordEvent(event); |
| 159 | + } |
| 160 | + } |
| 161 | + // |
| 162 | + // @Bean("TestRegion1") ReplicatedRegionFactoryBean getTestRegion(GemFireCache cache) { |
| 163 | + // return createRegionFactoryBean(cache, "TestRegion1"); |
| 164 | + // } |
| 165 | + // |
| 166 | + // @AsCacheListener(eventTypes = CacheListenerEventType.AFTER_CREATE) |
| 167 | + // public void afterCreateListener(EntryEvent event) { |
| 168 | + // recordEvent(event); |
| 169 | + // } |
| 170 | + // |
| 171 | + // @AsCacheListener(eventTypes = CacheListenerEventType.AFTER_UPDATE) |
| 172 | + // public void afterUpdateListener(EntryEvent event) { |
| 173 | + // recordEvent(event); |
| 174 | + // |
| 175 | + // } |
| 176 | + //} |
| 177 | + // |
| 178 | + //@Configuration @CacheServerApplication @EnableEventProcessing |
| 179 | + //public static class TestConfigurationWithInvalidRegion { |
| 180 | + // |
| 181 | + // @Bean("TestRegion1") ReplicatedRegionFactoryBean getTestRegion(GemFireCache cache) { |
| 182 | + // return createRegionFactoryBean(cache, "TestRegion1"); |
| 183 | + // } |
| 184 | + // |
| 185 | + // @AsCacheListener(eventTypes = CacheListenerEventType.AFTER_CREATE, regions = "TestRegion2") |
| 186 | + // public void afterCreateListener(EntryEvent event) { |
| 187 | + // recordEvent(event); |
| 188 | + // } |
| 189 | + // |
| 190 | + //} |
| 191 | + // |
| 192 | + //@Configuration @CacheServerApplication @EnableEventProcessing |
| 193 | + //public static class TestConfigurationWithSimpleCacheListenerAllEvents { |
| 194 | + // |
| 195 | + // @Bean("TestRegion1") ReplicatedRegionFactoryBean getTestRegion(GemFireCache cache) { |
| 196 | + // return createRegionFactoryBean(cache, "TestRegion1"); |
| 197 | + // } |
| 198 | + // |
| 199 | + // @AsCacheListener(eventTypes = CacheListenerEventType.ALL) public void afterCreateListener(EntryEvent event) { |
| 200 | + // recordEvent(event); |
| 201 | + // } |
| 202 | + //} |
| 203 | + // |
| 204 | + //@Configuration @CacheServerApplication @EnableEventProcessing |
| 205 | + //public static class TestConfigurationWithSimpleCacheListenerWith2Regions { |
| 206 | + // |
| 207 | + // @Bean("TestRegion1") ReplicatedRegionFactoryBean getTestRegion1(GemFireCache cache) { |
| 208 | + // return createRegionFactoryBean(cache, "TestRegion1"); |
| 209 | + // } |
| 210 | + // |
| 211 | + // @Bean("TestRegion2") ReplicatedRegionFactoryBean getTestRegion2(GemFireCache cache) { |
| 212 | + // return createRegionFactoryBean(cache, "TestRegion2"); |
| 213 | + // } |
| 214 | + // |
| 215 | + // @AsCacheListener(eventTypes = CacheListenerEventType.AFTER_CREATE, regions = "TestRegion1") |
| 216 | + // public void afterCreateListener(EntryEvent event) { |
| 217 | + // recordEvent(event); |
| 218 | + // } |
| 219 | + // |
| 220 | + // @AsCacheListener(eventTypes = CacheListenerEventType.AFTER_CREATE, regions = "TestRegion2") |
| 221 | + // public void afterUpdateListener(EntryEvent event) { |
| 222 | + // recordEvent(event); |
| 223 | + // |
| 224 | + // } |
| 225 | + //} |
| 226 | + // |
| 227 | + //@Configuration @CacheServerApplication @EnableEventProcessing |
| 228 | + //public static class TestConfigurationWith2RegionsAnd2CacheListenersDefaulted { |
| 229 | + // |
| 230 | + // @Bean("TestRegion1") ReplicatedRegionFactoryBean getTestRegion1(GemFireCache cache) { |
| 231 | + // return createRegionFactoryBean(cache, "TestRegion1"); |
| 232 | + // } |
| 233 | + // |
| 234 | + // @Bean("TestRegion2") ReplicatedRegionFactoryBean getTestRegion2(GemFireCache cache) { |
| 235 | + // return createRegionFactoryBean(cache, "TestRegion2"); |
| 236 | + // } |
| 237 | + // |
| 238 | + // @AsCacheListener(eventTypes = CacheListenerEventType.ALL) public void afterCreateListener1(EntryEvent event) { |
| 239 | + // recordEvent(event); |
| 240 | + // } |
| 241 | + // |
| 242 | + // @AsCacheListener(eventTypes = CacheListenerEventType.ALL) public void afterCreateListener2(EntryEvent event) { |
| 243 | + // recordEvent(event); |
| 244 | + // |
| 245 | + // } |
| 246 | + //} |
| 247 | +} |
0 commit comments