| /* |
| * Licensed to the Apache Software Foundation (ASF) under one or more |
| * contributor license agreements. See the NOTICE file distributed with |
| * this work for additional information regarding copyright ownership. |
| * The ASF licenses this file to You under the Apache License, Version 2.0 |
| * (the "License"); you may not use this file except in compliance with |
| * the License. You may obtain a copy of the License at |
| * |
| * http://www.apache.org/licenses/LICENSE-2.0 |
| * |
| * Unless required by applicable law or agreed to in writing, software |
| * distributed under the License is distributed on an "AS IS" BASIS, |
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| * See the License for the specific language governing permissions and |
| * limitations under the License. |
| */ |
| |
| package org.apache.ignite.internal.storage.pagememory; |
| |
| import static org.apache.ignite.internal.pagememory.persistence.checkpoint.CheckpointState.FINISHED; |
| import static org.hamcrest.CoreMatchers.instanceOf; |
| import static org.hamcrest.CoreMatchers.is; |
| import static org.hamcrest.MatcherAssert.assertThat; |
| import static org.junit.jupiter.api.Assertions.assertEquals; |
| |
| import java.nio.file.Path; |
| import java.util.List; |
| import java.util.concurrent.TimeUnit; |
| import java.util.stream.Collectors; |
| import java.util.stream.IntStream; |
| import org.apache.ignite.configuration.schemas.store.UnknownDataStorageConfigurationSchema; |
| import org.apache.ignite.configuration.schemas.table.ConstantValueDefaultConfigurationSchema; |
| import org.apache.ignite.configuration.schemas.table.FunctionCallDefaultConfigurationSchema; |
| import org.apache.ignite.configuration.schemas.table.HashIndexConfigurationSchema; |
| import org.apache.ignite.configuration.schemas.table.NullValueDefaultConfigurationSchema; |
| import org.apache.ignite.configuration.schemas.table.TableConfiguration; |
| import org.apache.ignite.internal.components.LongJvmPauseDetector; |
| import org.apache.ignite.internal.configuration.testframework.ConfigurationExtension; |
| import org.apache.ignite.internal.configuration.testframework.InjectConfiguration; |
| import org.apache.ignite.internal.logger.Loggers; |
| import org.apache.ignite.internal.pagememory.configuration.schema.UnsafeMemoryAllocatorConfigurationSchema; |
| import org.apache.ignite.internal.pagememory.io.PageIoRegistry; |
| import org.apache.ignite.internal.storage.AbstractPartitionStorageTest; |
| import org.apache.ignite.internal.storage.DataRow; |
| import org.apache.ignite.internal.storage.engine.TableStorage; |
| import org.apache.ignite.internal.storage.pagememory.configuration.schema.PersistentPageMemoryDataStorageChange; |
| import org.apache.ignite.internal.storage.pagememory.configuration.schema.PersistentPageMemoryDataStorageConfigurationSchema; |
| import org.apache.ignite.internal.storage.pagememory.configuration.schema.PersistentPageMemoryDataStorageView; |
| import org.apache.ignite.internal.storage.pagememory.configuration.schema.PersistentPageMemoryStorageEngineConfiguration; |
| import org.apache.ignite.internal.storage.pagememory.configuration.schema.PersistentPageMemoryStorageEngineConfigurationSchema; |
| import org.apache.ignite.internal.testframework.WorkDirectory; |
| import org.apache.ignite.internal.testframework.WorkDirectoryExtension; |
| import org.apache.ignite.internal.util.IgniteUtils; |
| import org.junit.jupiter.api.AfterAll; |
| import org.junit.jupiter.api.AfterEach; |
| import org.junit.jupiter.api.BeforeAll; |
| import org.junit.jupiter.api.BeforeEach; |
| import org.junit.jupiter.api.Disabled; |
| import org.junit.jupiter.api.Test; |
| import org.junit.jupiter.api.extension.ExtendWith; |
| |
| /** |
| * Storage test implementation for {@link PersistentPageMemoryPartitionStorage}. |
| */ |
| @ExtendWith(ConfigurationExtension.class) |
| @ExtendWith(WorkDirectoryExtension.class) |
| public class PersistentPageMemoryPartitionStorageTest extends AbstractPartitionStorageTest { |
| private static PageIoRegistry ioRegistry; |
| |
| @InjectConfiguration(polymorphicExtensions = UnsafeMemoryAllocatorConfigurationSchema.class) |
| PersistentPageMemoryStorageEngineConfiguration engineConfig; |
| |
| @InjectConfiguration( |
| name = "table", |
| polymorphicExtensions = { |
| HashIndexConfigurationSchema.class, |
| UnknownDataStorageConfigurationSchema.class, |
| PersistentPageMemoryDataStorageConfigurationSchema.class, |
| ConstantValueDefaultConfigurationSchema.class, |
| FunctionCallDefaultConfigurationSchema.class, |
| NullValueDefaultConfigurationSchema.class, |
| } |
| ) |
| private TableConfiguration tableCfg; |
| |
| private LongJvmPauseDetector longJvmPauseDetector; |
| |
| private PersistentPageMemoryStorageEngine engine; |
| |
| private TableStorage table; |
| |
| @WorkDirectory |
| private Path workDir; |
| |
| @BeforeAll |
| static void beforeAll() { |
| ioRegistry = new PageIoRegistry(); |
| |
| ioRegistry.loadFromServiceLoader(); |
| } |
| |
| @BeforeEach |
| void setUp() throws Exception { |
| String nodeName = "test-node"; |
| |
| longJvmPauseDetector = new LongJvmPauseDetector(nodeName, Loggers.forClass(LongJvmPauseDetector.class)); |
| |
| longJvmPauseDetector.start(); |
| |
| engine = new PersistentPageMemoryStorageEngine(nodeName, engineConfig, ioRegistry, workDir, longJvmPauseDetector); |
| |
| engine.start(); |
| |
| tableCfg |
| .change(c -> c.changeDataStorage(dsc -> dsc.convert(PersistentPageMemoryDataStorageChange.class))) |
| .get(1, TimeUnit.SECONDS); |
| |
| assertEquals( |
| PersistentPageMemoryStorageEngineConfigurationSchema.DEFAULT_DATA_REGION_NAME, |
| ((PersistentPageMemoryDataStorageView) tableCfg.dataStorage().value()).dataRegion() |
| ); |
| |
| table = engine.createTable(tableCfg); |
| |
| assertThat(table, is(instanceOf(PersistentPageMemoryTableStorage.class))); |
| |
| table.start(); |
| |
| storage = table.getOrCreatePartition(0); |
| |
| assertThat(storage, is(instanceOf(PersistentPageMemoryPartitionStorage.class))); |
| } |
| |
| @AfterEach |
| void tearDown() throws Exception { |
| IgniteUtils.closeAll( |
| storage, |
| table == null ? null : table::stop, |
| engine == null ? null : engine::stop, |
| longJvmPauseDetector == null ? null : longJvmPauseDetector::stop |
| ); |
| } |
| |
| @AfterAll |
| static void afterAll() { |
| ioRegistry = null; |
| } |
| |
| /** {@inheritDoc} */ |
| @Test |
| @Override |
| @Disabled("https://issues.apache.org/jira/browse/IGNITE-16644") |
| public void testSnapshot(@WorkDirectory Path workDir) throws Exception { |
| super.testSnapshot(workDir); |
| } |
| |
| @Test |
| void testReadAfterRestart() throws Exception { |
| List<DataRow> rows = IntStream.range(0, 100) |
| .mapToObj(i -> dataRow(KEY + i, VALUE + i)) |
| .collect(Collectors.toList()); |
| |
| storage.writeAll(rows); |
| |
| engine |
| .checkpointManager() |
| .forceCheckpoint("before_stop_engine") |
| .futureFor(FINISHED) |
| .get(1, TimeUnit.SECONDS); |
| |
| tearDown(); |
| |
| setUp(); |
| |
| rows.forEach(this::checkHasSameEntry); |
| } |
| } |