|
| 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.persistence.db.checkpoint; |
| 19 | + |
| 20 | +import java.util.concurrent.CountDownLatch; |
| 21 | +import java.util.concurrent.TimeUnit; |
| 22 | +import org.apache.ignite.cluster.ClusterState; |
| 23 | +import org.apache.ignite.configuration.DataRegionConfiguration; |
| 24 | +import org.apache.ignite.configuration.DataStorageConfiguration; |
| 25 | +import org.apache.ignite.configuration.IgniteConfiguration; |
| 26 | +import org.apache.ignite.internal.IgniteEx; |
| 27 | +import org.apache.ignite.internal.processors.cache.persistence.GridCacheDatabaseSharedManager; |
| 28 | +import org.apache.ignite.internal.processors.cache.persistence.checkpoint.CheckpointListener; |
| 29 | +import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest; |
| 30 | +import org.junit.Test; |
| 31 | + |
| 32 | +/** |
| 33 | + * Test of CheckpointTimeoutLock. |
| 34 | + */ |
| 35 | +public class CheckpointTimeoutLockTest extends GridCommonAbstractTest { |
| 36 | + /** {@inheritDoc} */ |
| 37 | + @Override protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception { |
| 38 | + return super.getConfiguration(igniteInstanceName).setDataStorageConfiguration( |
| 39 | + new DataStorageConfiguration().setDefaultDataRegionConfiguration( |
| 40 | + new DataRegionConfiguration().setPersistenceEnabled(true))); |
| 41 | + } |
| 42 | + |
| 43 | + /** |
| 44 | + * @throws Exception if failed. |
| 45 | + */ |
| 46 | + @Test |
| 47 | + public void testLockIsHeldByThreadAfterTimeout() throws Exception { |
| 48 | + IgniteEx ignite = startGrid(); |
| 49 | + |
| 50 | + ignite.cluster().state(ClusterState.ACTIVE); |
| 51 | + |
| 52 | + GridCacheDatabaseSharedManager db = dbMgr(ignite); |
| 53 | + |
| 54 | + CountDownLatch latch = new CountDownLatch(1); |
| 55 | + |
| 56 | + db.addCheckpointListener(new CheckpointListener() { |
| 57 | + @Override public void onMarkCheckpointBegin(Context ctx) { |
| 58 | + latch.countDown(); |
| 59 | + |
| 60 | + doSleep(200L); |
| 61 | + } |
| 62 | + |
| 63 | + @Override public void onCheckpointBegin(Context ctx) { |
| 64 | + // No-op. |
| 65 | + } |
| 66 | + |
| 67 | + @Override public void beforeCheckpointBegin(Context ctx) { |
| 68 | + // No-op. |
| 69 | + } |
| 70 | + }); |
| 71 | + |
| 72 | + db.forceCheckpoint("lock"); |
| 73 | + |
| 74 | + latch.await(getTestTimeout(), TimeUnit.MILLISECONDS); |
| 75 | + |
| 76 | + db.checkpointReadLockTimeout(10L); |
| 77 | + db.checkpointReadLock(); |
| 78 | + db.checkpointReadUnlock(); |
| 79 | + assertFalse(db.checkpointLockIsHeldByThread()); |
| 80 | + } |
| 81 | +} |
0 commit comments