|
| 1 | +/* |
| 2 | + * Licensed to the Apache Software Foundation (ASF) under one or more |
| 3 | + * contributor license agreements. See the NOTICE file distributed with |
| 4 | + * this work for additional information regarding copyright ownership. |
| 5 | + * The ASF licenses this file to You under the Apache License, Version 2.0 |
| 6 | + * (the "License"); you may not use this file except in compliance with |
| 7 | + * the License. You may obtain a copy of the License at |
| 8 | + * |
| 9 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | + * |
| 11 | + * Unless required by applicable law or agreed to in writing, software |
| 12 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | + * See the License for the specific language governing permissions and |
| 15 | + * limitations under the License. |
| 16 | + */ |
| 17 | + |
| 18 | +package org.apache.ignite.internal.processors.cache; |
| 19 | + |
| 20 | +import java.util.concurrent.ThreadLocalRandom; |
| 21 | +import org.apache.ignite.IgniteCache; |
| 22 | +import org.apache.ignite.IgniteSystemProperties; |
| 23 | +import org.apache.ignite.configuration.CacheConfiguration; |
| 24 | +import org.apache.ignite.configuration.IgniteConfiguration; |
| 25 | +import org.apache.ignite.internal.IgniteEx; |
| 26 | +import org.apache.ignite.internal.TestRecordingCommunicationSpi; |
| 27 | +import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest; |
| 28 | +import org.junit.Test; |
| 29 | + |
| 30 | +/** */ |
| 31 | +public class CacheMdcGetTest extends GridCommonAbstractTest { |
| 32 | + /** */ |
| 33 | + private static final String DC_ID_0 = "DC0"; |
| 34 | + |
| 35 | + /** */ |
| 36 | + private static final String DC_ID_1 = "DC1"; |
| 37 | + |
| 38 | + /** */ |
| 39 | + private static final String KEY = "key"; |
| 40 | + |
| 41 | + /** */ |
| 42 | + private static final String VAL = "val"; |
| 43 | + |
| 44 | + /** {@inheritDoc} */ |
| 45 | + @Override protected void afterTest() throws Exception { |
| 46 | + super.afterTest(); |
| 47 | + |
| 48 | + stopAllGrids(); |
| 49 | + } |
| 50 | + |
| 51 | + /** {@inheritDoc} */ |
| 52 | + @Override protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception { |
| 53 | + return super.getConfiguration(igniteInstanceName) |
| 54 | + .setCommunicationSpi(new TestRecordingCommunicationSpi()); |
| 55 | + } |
| 56 | + |
| 57 | + /** */ |
| 58 | + @Test |
| 59 | + public void test() throws Exception { |
| 60 | + ThreadLocalRandom rnd = ThreadLocalRandom.current(); |
| 61 | + |
| 62 | + boolean bool = rnd.nextBoolean(); |
| 63 | + |
| 64 | + System.setProperty(IgniteSystemProperties.IGNITE_DATA_CENTER_ID, bool ? DC_ID_0 : DC_ID_1); |
| 65 | + |
| 66 | + startGrid(0); |
| 67 | + |
| 68 | + System.setProperty(IgniteSystemProperties.IGNITE_DATA_CENTER_ID, bool ? DC_ID_1 : DC_ID_0); |
| 69 | + |
| 70 | + startGrid(1); |
| 71 | + |
| 72 | + waitForTopology(2); |
| 73 | + |
| 74 | + System.setProperty(IgniteSystemProperties.IGNITE_DATA_CENTER_ID, DC_ID_1); |
| 75 | + |
| 76 | + IgniteEx client = startClientGrid(); |
| 77 | + |
| 78 | + CacheConfiguration<Object, Object> ccfg = new CacheConfiguration<>(DEFAULT_CACHE_NAME); |
| 79 | + |
| 80 | + ccfg.setBackups(1); |
| 81 | + |
| 82 | + IgniteCache<Object, Object> cache = client.createCache(ccfg); |
| 83 | + |
| 84 | + cache.put(KEY, VAL); |
| 85 | + |
| 86 | + TestRecordingCommunicationSpi spi = TestRecordingCommunicationSpi.spi(bool ? grid(0) : grid(1)); |
| 87 | + |
| 88 | + spi.blockMessages((n, msg) -> true); |
| 89 | + |
| 90 | + assertEquals(VAL, cache.get(KEY)); |
| 91 | + } |
| 92 | +} |
0 commit comments