diff --git a/community/kernel/src/main/java/org/neo4j/kernel/impl/store/format/StoreVersions.java b/community/kernel/src/main/java/org/neo4j/kernel/impl/store/format/StoreVersion.java similarity index 52% rename from community/kernel/src/main/java/org/neo4j/kernel/impl/store/format/StoreVersions.java rename to community/kernel/src/main/java/org/neo4j/kernel/impl/store/format/StoreVersion.java index d388b5c72f608..ff5809aaf7f7e 100644 --- a/community/kernel/src/main/java/org/neo4j/kernel/impl/store/format/StoreVersions.java +++ b/community/kernel/src/main/java/org/neo4j/kernel/impl/store/format/StoreVersion.java @@ -24,39 +24,61 @@ /** * All known store formats are collected here. */ -public class StoreVersions +public enum StoreVersion { - // Community formats - public static final String STANDARD_V2_0 = "v0.A.1"; - public static final String STANDARD_V2_1 = "v0.A.3"; - public static final String STANDARD_V2_2 = "v0.A.5"; - public static final String STANDARD_V2_3 = "v0.A.6"; - public static final String STANDARD_V3_0 = "v0.A.7"; + STANDARD_V2_0( "v0.A.1", true ), + STANDARD_V2_1( "v0.A.3", true ), + STANDARD_V2_2( "v0.A.5", true ), + STANDARD_V2_3( "v0.A.6", true ), + STANDARD_V3_0( "v0.A.7", true ), - // Enterprise formats - public static final String HIGH_LIMIT_V3_0 = "vE.H.0"; + HIGH_LIMIT_V3_0( "vE.H.0", false ); + + private static final StoreVersion[] ALL_STORE_VERSIONS = values(); + + private final String string; + private final boolean isCommunity; + + StoreVersion( String string, boolean isCommunity ) + { + this.string = string; + this.isCommunity = isCommunity; + } + + public String string() + { + return string; + } /** - * - * @param storeVersion string + * @param version string * @return true if the store version is a known community format, false otherwise */ - public static boolean isCommunityStoreVersion( @Nonnull String storeVersion ) + public static boolean isCommunityStoreVersion( @Nonnull String version ) { - return STANDARD_V2_0.equals( storeVersion ) || - STANDARD_V2_1.equals( storeVersion ) || - STANDARD_V2_2.equals( storeVersion ) || - STANDARD_V2_3.equals( storeVersion ) || - STANDARD_V3_0.equals( storeVersion ); + for ( StoreVersion storeVersion : ALL_STORE_VERSIONS ) + { + if ( storeVersion.string.equals( version ) && storeVersion.isCommunity ) + { + return true; + } + } + return false; } /** - * - * @param storeVersion string + * @param version string * @return true if the store version is a known enterprise format, false otherwise */ - public static boolean isEnterpriseStoreVersion( @Nonnull String storeVersion ) + public static boolean isEnterpriseStoreVersion( @Nonnull String version ) { - return HIGH_LIMIT_V3_0.equals( storeVersion ); + for ( StoreVersion storeVersion : ALL_STORE_VERSIONS ) + { + if ( storeVersion.string.equals( version ) && !storeVersion.isCommunity ) + { + return true; + } + } + return false; } } diff --git a/community/kernel/src/main/java/org/neo4j/kernel/impl/store/format/standard/StandardV2_0.java b/community/kernel/src/main/java/org/neo4j/kernel/impl/store/format/standard/StandardV2_0.java index af8502379ca73..48e4248b0599a 100644 --- a/community/kernel/src/main/java/org/neo4j/kernel/impl/store/format/standard/StandardV2_0.java +++ b/community/kernel/src/main/java/org/neo4j/kernel/impl/store/format/standard/StandardV2_0.java @@ -23,7 +23,7 @@ import org.neo4j.kernel.impl.store.format.Capability; import org.neo4j.kernel.impl.store.format.RecordFormat; import org.neo4j.kernel.impl.store.format.RecordFormats; -import org.neo4j.kernel.impl.store.format.StoreVersions; +import org.neo4j.kernel.impl.store.format.StoreVersion; import org.neo4j.kernel.impl.store.record.DynamicRecord; import org.neo4j.kernel.impl.store.record.LabelTokenRecord; import org.neo4j.kernel.impl.store.record.NodeRecord; @@ -35,8 +35,8 @@ public class StandardV2_0 extends BaseRecordFormats { + public static final String STORE_VERSION = StoreVersion.STANDARD_V2_0.string(); public static final RecordFormats RECORD_FORMATS = new StandardV2_0(); - public static final String STORE_VERSION = StoreVersions.STANDARD_V2_0; public StandardV2_0() { diff --git a/community/kernel/src/main/java/org/neo4j/kernel/impl/store/format/standard/StandardV2_1.java b/community/kernel/src/main/java/org/neo4j/kernel/impl/store/format/standard/StandardV2_1.java index becc9a0deb1b6..8672799d88d63 100644 --- a/community/kernel/src/main/java/org/neo4j/kernel/impl/store/format/standard/StandardV2_1.java +++ b/community/kernel/src/main/java/org/neo4j/kernel/impl/store/format/standard/StandardV2_1.java @@ -23,7 +23,7 @@ import org.neo4j.kernel.impl.store.format.Capability; import org.neo4j.kernel.impl.store.format.RecordFormat; import org.neo4j.kernel.impl.store.format.RecordFormats; -import org.neo4j.kernel.impl.store.format.StoreVersions; +import org.neo4j.kernel.impl.store.format.StoreVersion; import org.neo4j.kernel.impl.store.record.DynamicRecord; import org.neo4j.kernel.impl.store.record.LabelTokenRecord; import org.neo4j.kernel.impl.store.record.NodeRecord; @@ -35,8 +35,8 @@ public class StandardV2_1 extends BaseRecordFormats { + public static final String STORE_VERSION = StoreVersion.STANDARD_V2_1.string(); public static final RecordFormats RECORD_FORMATS = new StandardV2_1(); - public static final String STORE_VERSION = StoreVersions.STANDARD_V2_1; public StandardV2_1() { diff --git a/community/kernel/src/main/java/org/neo4j/kernel/impl/store/format/standard/StandardV2_2.java b/community/kernel/src/main/java/org/neo4j/kernel/impl/store/format/standard/StandardV2_2.java index 8ca087c17b245..372f06f88280a 100644 --- a/community/kernel/src/main/java/org/neo4j/kernel/impl/store/format/standard/StandardV2_2.java +++ b/community/kernel/src/main/java/org/neo4j/kernel/impl/store/format/standard/StandardV2_2.java @@ -23,7 +23,7 @@ import org.neo4j.kernel.impl.store.format.Capability; import org.neo4j.kernel.impl.store.format.RecordFormat; import org.neo4j.kernel.impl.store.format.RecordFormats; -import org.neo4j.kernel.impl.store.format.StoreVersions; +import org.neo4j.kernel.impl.store.format.StoreVersion; import org.neo4j.kernel.impl.store.record.DynamicRecord; import org.neo4j.kernel.impl.store.record.LabelTokenRecord; import org.neo4j.kernel.impl.store.record.NodeRecord; @@ -35,12 +35,12 @@ public class StandardV2_2 extends BaseRecordFormats { + public static final String STORE_VERSION = StoreVersion.STANDARD_V2_2.string(); public static final RecordFormats RECORD_FORMATS = new StandardV2_2(); - public static final String STORE_VERSION = StoreVersions.STANDARD_V2_2; public StandardV2_2() { - super( STORE_VERSION, 5, Capability.SCHEMA, Capability.DENSE_NODES, Capability.LUCENE_3, + super( STORE_VERSION, 4, Capability.SCHEMA, Capability.DENSE_NODES, Capability.LUCENE_3, Capability.VERSION_TRAILERS ); } diff --git a/community/kernel/src/main/java/org/neo4j/kernel/impl/store/format/standard/StandardV2_3.java b/community/kernel/src/main/java/org/neo4j/kernel/impl/store/format/standard/StandardV2_3.java index dff28431cb78a..f5a527dfdff0e 100644 --- a/community/kernel/src/main/java/org/neo4j/kernel/impl/store/format/standard/StandardV2_3.java +++ b/community/kernel/src/main/java/org/neo4j/kernel/impl/store/format/standard/StandardV2_3.java @@ -23,7 +23,7 @@ import org.neo4j.kernel.impl.store.format.Capability; import org.neo4j.kernel.impl.store.format.RecordFormat; import org.neo4j.kernel.impl.store.format.RecordFormats; -import org.neo4j.kernel.impl.store.format.StoreVersions; +import org.neo4j.kernel.impl.store.format.StoreVersion; import org.neo4j.kernel.impl.store.record.DynamicRecord; import org.neo4j.kernel.impl.store.record.LabelTokenRecord; import org.neo4j.kernel.impl.store.record.NodeRecord; @@ -35,12 +35,12 @@ public class StandardV2_3 extends BaseRecordFormats { + public static final String STORE_VERSION = StoreVersion.STANDARD_V2_3.string(); public static final RecordFormats RECORD_FORMATS = new StandardV2_3(); - public static final String STORE_VERSION = StoreVersions.STANDARD_V2_3; public StandardV2_3() { - super( STORE_VERSION, 4, Capability.SCHEMA, Capability.DENSE_NODES, Capability.LUCENE_3 ); + super( STORE_VERSION, 5, Capability.SCHEMA, Capability.DENSE_NODES, Capability.LUCENE_3 ); } @Override diff --git a/community/kernel/src/main/java/org/neo4j/kernel/impl/store/format/standard/StandardV3_0.java b/community/kernel/src/main/java/org/neo4j/kernel/impl/store/format/standard/StandardV3_0.java index 2c593bc60a31f..cd451c7389eb9 100644 --- a/community/kernel/src/main/java/org/neo4j/kernel/impl/store/format/standard/StandardV3_0.java +++ b/community/kernel/src/main/java/org/neo4j/kernel/impl/store/format/standard/StandardV3_0.java @@ -23,7 +23,7 @@ import org.neo4j.kernel.impl.store.format.Capability; import org.neo4j.kernel.impl.store.format.RecordFormat; import org.neo4j.kernel.impl.store.format.RecordFormats; -import org.neo4j.kernel.impl.store.format.StoreVersions; +import org.neo4j.kernel.impl.store.format.StoreVersion; import org.neo4j.kernel.impl.store.record.DynamicRecord; import org.neo4j.kernel.impl.store.record.LabelTokenRecord; import org.neo4j.kernel.impl.store.record.NodeRecord; @@ -35,13 +35,13 @@ public class StandardV3_0 extends BaseRecordFormats { + public static final String STORE_VERSION = StoreVersion.STANDARD_V3_0.string(); public static final RecordFormats RECORD_FORMATS = new StandardV3_0(); - public static final String STORE_VERSION = StoreVersions.STANDARD_V3_0; public static final String NAME = "standard"; public StandardV3_0() { - super( STORE_VERSION, 5, Capability.SCHEMA, Capability.DENSE_NODES, Capability.LUCENE_5 ); + super( STORE_VERSION, 6, Capability.SCHEMA, Capability.DENSE_NODES, Capability.LUCENE_5 ); } @Override diff --git a/community/kernel/src/main/java/org/neo4j/kernel/impl/storemigration/UpgradableDatabase.java b/community/kernel/src/main/java/org/neo4j/kernel/impl/storemigration/UpgradableDatabase.java index 83064e5db354f..97420f5c2f370 100644 --- a/community/kernel/src/main/java/org/neo4j/kernel/impl/storemigration/UpgradableDatabase.java +++ b/community/kernel/src/main/java/org/neo4j/kernel/impl/storemigration/UpgradableDatabase.java @@ -27,10 +27,10 @@ import org.neo4j.kernel.impl.store.format.Capability; import org.neo4j.kernel.impl.store.format.RecordFormatSelector; import org.neo4j.kernel.impl.store.format.RecordFormats; -import org.neo4j.kernel.impl.store.format.StoreVersions; +import org.neo4j.kernel.impl.store.format.StoreVersion; import org.neo4j.kernel.impl.storemigration.StoreUpgrader.DatabaseNotCleanlyShutDownException; -import org.neo4j.kernel.impl.storemigration.StoreUpgrader.UnexpectedUpgradingStoreVersionException; import org.neo4j.kernel.impl.storemigration.StoreUpgrader.UnexpectedUpgradingStoreFormatException; +import org.neo4j.kernel.impl.storemigration.StoreUpgrader.UnexpectedUpgradingStoreVersionException; import org.neo4j.kernel.impl.storemigration.StoreUpgrader.UpgradeMissingStoreFilesException; import org.neo4j.kernel.impl.storemigration.StoreUpgrader.UpgradingStoreVersionNotFoundException; import org.neo4j.kernel.impl.storemigration.StoreVersionCheck.Result; @@ -90,8 +90,8 @@ public RecordFormats checkUpgradeable( File storeDirectory ) // If we are trying to open an enterprise store when configured to use community format, then inform the user // of the config setting to change since downgrades aren't possible but the store can still be opened. - if ( StoreVersions.isEnterpriseStoreVersion( result.actualVersion ) && - StoreVersions.isCommunityStoreVersion( format.storeVersion() ) ) + if ( StoreVersion.isEnterpriseStoreVersion( result.actualVersion ) && + StoreVersion.isCommunityStoreVersion( format.storeVersion() ) ) { throw new StoreUpgrader.UnexpectedUpgradingStoreFormatException(); } diff --git a/community/kernel/src/main/java/org/neo4j/kernel/impl/storemigration/participant/StoreMigrator.java b/community/kernel/src/main/java/org/neo4j/kernel/impl/storemigration/participant/StoreMigrator.java index f44db80a235d7..dafd86d9991f3 100644 --- a/community/kernel/src/main/java/org/neo4j/kernel/impl/storemigration/participant/StoreMigrator.java +++ b/community/kernel/src/main/java/org/neo4j/kernel/impl/storemigration/participant/StoreMigrator.java @@ -30,6 +30,7 @@ import java.util.Arrays; import java.util.Collection; import java.util.List; +import java.util.Objects; import java.util.Random; import java.util.function.BiConsumer; @@ -39,7 +40,6 @@ import org.neo4j.kernel.api.index.SchemaIndexProvider; import org.neo4j.kernel.configuration.Config; import org.neo4j.kernel.impl.api.store.StorePropertyCursor; -import org.neo4j.kernel.impl.locking.LockService; import org.neo4j.kernel.impl.logging.LogService; import org.neo4j.kernel.impl.store.CountsComputer; import org.neo4j.kernel.impl.store.MetaDataStore; @@ -597,10 +597,9 @@ public void moveMigratedFiles( File migrationDir, File storeDir, String versionT public void rebuildCounts( File storeDir, String versionToMigrateFrom, String versionToMigrateTo ) throws IOException { - switch ( versionToMigrateFrom ) + if ( Objects.equals( versionToMigrateFrom, StandardV2_1.STORE_VERSION ) || + Objects.equals( versionToMigrateFrom, StandardV2_2.STORE_VERSION ) ) { - case StandardV2_1.STORE_VERSION: - case StandardV2_2.STORE_VERSION: // create counters from scratch Iterable countsStoreFiles = Iterables.iterable( StoreFile.COUNTS_STORE_LEFT, StoreFile.COUNTS_STORE_RIGHT ); @@ -609,9 +608,6 @@ public void rebuildCounts( File storeDir, String versionToMigrateFrom, String ve File neoStore = new File( storeDir, DEFAULT_NAME ); long lastTxId = MetaDataStore.getRecord( pageCache, neoStore, Position.LAST_TRANSACTION_ID ); rebuildCountsFromScratch( storeDir, lastTxId, pageCache, selectForVersion( versionToMigrateTo ) ); - break; - default: - // OK, don't rebuild for other versions } } diff --git a/community/kernel/src/test/java/org/neo4j/kernel/impl/store/format/StoreVersionsTest.java b/community/kernel/src/test/java/org/neo4j/kernel/impl/store/format/StoreVersionTest.java similarity index 73% rename from community/kernel/src/test/java/org/neo4j/kernel/impl/store/format/StoreVersionsTest.java rename to community/kernel/src/test/java/org/neo4j/kernel/impl/store/format/StoreVersionTest.java index 453f49ab98866..34f212e167f0c 100644 --- a/community/kernel/src/test/java/org/neo4j/kernel/impl/store/format/StoreVersionsTest.java +++ b/community/kernel/src/test/java/org/neo4j/kernel/impl/store/format/StoreVersionTest.java @@ -26,10 +26,11 @@ import java.util.Arrays; import java.util.Collection; -import static org.junit.Assert.*; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; @RunWith( Parameterized.class ) -public class StoreVersionsTest +public class StoreVersionTest { @Parameterized.Parameter( 0 ) public String version; @@ -37,20 +38,24 @@ public class StoreVersionsTest @Parameterized.Parameters( name = "{0}" ) public static Collection versions() { - return Arrays.asList( StoreVersions.STANDARD_V2_0, StoreVersions.STANDARD_V2_1, StoreVersions.STANDARD_V2_2, - StoreVersions.STANDARD_V2_3, StoreVersions.STANDARD_V3_0 ); + return Arrays.asList( + StoreVersion.STANDARD_V2_0.string(), + StoreVersion.STANDARD_V2_1.string(), + StoreVersion.STANDARD_V2_2.string(), + StoreVersion.STANDARD_V2_3.string(), + StoreVersion.STANDARD_V3_0.string() ); } @Test public void shouldBeCommunityFormat() { - assertTrue( "Expected community format", StoreVersions.isCommunityStoreVersion( version ) ); + assertTrue( "Expected community format", StoreVersion.isCommunityStoreVersion( version ) ); } @Test public void shouldNotBeLabeledEnterpriseFormat() { - assertFalse( "Expected non-enterprise format", StoreVersions.isEnterpriseStoreVersion( version ) ); + assertFalse( "Expected non-enterprise format", StoreVersion.isEnterpriseStoreVersion( version ) ); } @RunWith( Parameterized.class ) @@ -62,19 +67,19 @@ public static class EnterpriseVersions @Parameterized.Parameters( name = "{0}" ) public static Collection versions() { - return Arrays.asList( StoreVersions.HIGH_LIMIT_V3_0 ); + return Arrays.asList( StoreVersion.HIGH_LIMIT_V3_0.string() ); } @Test public void shouldBeCommunityFormat() { - assertFalse( "Expected non-community format", StoreVersions.isCommunityStoreVersion( version ) ); + assertFalse( "Expected non-community format", StoreVersion.isCommunityStoreVersion( version ) ); } @Test public void shouldNotBeLabeledEnterpriseFormat() { - assertTrue( "Expected enterprise format", StoreVersions.isEnterpriseStoreVersion( version ) ); + assertTrue( "Expected enterprise format", StoreVersion.isEnterpriseStoreVersion( version ) ); } } } diff --git a/community/kernel/src/test/java/org/neo4j/kernel/impl/storemigration/MigrationTestUtils.java b/community/kernel/src/test/java/org/neo4j/kernel/impl/storemigration/MigrationTestUtils.java index 1d0f9ee7c61f9..a22eb12c508fd 100644 --- a/community/kernel/src/test/java/org/neo4j/kernel/impl/storemigration/MigrationTestUtils.java +++ b/community/kernel/src/test/java/org/neo4j/kernel/impl/storemigration/MigrationTestUtils.java @@ -148,17 +148,24 @@ public static void prepareSampleLegacyDatabase( String version, FileSystemAbstra public static File findFormatStoreDirectoryForVersion( String version, File targetDir ) throws IOException { - switch ( version ) + if ( version.equals( StandardV2_3.STORE_VERSION ) ) { - case StandardV2_3.STORE_VERSION: return find23FormatStoreDirectory( targetDir ); - case StandardV2_2.STORE_VERSION: + } + else if ( version.equals( StandardV2_2.STORE_VERSION ) ) + { return find22FormatStoreDirectory( targetDir ); - case StandardV2_1.STORE_VERSION: + } + else if ( version.equals( StandardV2_1.STORE_VERSION ) ) + { return find21FormatStoreDirectory( targetDir ); - case StandardV2_0.STORE_VERSION: + } + else if ( version.equals( StandardV2_0.STORE_VERSION ) ) + { return find20FormatStoreDirectory( targetDir ); - default: + } + else + { throw new IllegalArgumentException( "Unknown version" ); } } diff --git a/community/kernel/src/test/java/org/neo4j/kernel/impl/storemigration/UpgradableDatabaseTest.java b/community/kernel/src/test/java/org/neo4j/kernel/impl/storemigration/UpgradableDatabaseTest.java index c61ded317247c..98bf70622f67a 100644 --- a/community/kernel/src/test/java/org/neo4j/kernel/impl/storemigration/UpgradableDatabaseTest.java +++ b/community/kernel/src/test/java/org/neo4j/kernel/impl/storemigration/UpgradableDatabaseTest.java @@ -37,7 +37,7 @@ import org.neo4j.io.fs.FileSystemAbstraction; import org.neo4j.kernel.impl.store.MetaDataStore; import org.neo4j.kernel.impl.store.format.RecordFormats; -import org.neo4j.kernel.impl.store.format.StoreVersions; +import org.neo4j.kernel.impl.store.format.StoreVersion; import org.neo4j.kernel.impl.store.format.standard.StandardV2_0; import org.neo4j.kernel.impl.store.format.standard.StandardV2_1; import org.neo4j.kernel.impl.store.format.standard.StandardV2_2; @@ -211,7 +211,7 @@ public static class UnsupportedVersions @Parameterized.Parameters( name = "{0}" ) public static Collection versions() { - return Arrays.asList( "v0.9.5", "v0.A.4", StoreVersions.HIGH_LIMIT_V3_0 ); + return Arrays.asList( "v0.9.5", "v0.A.4", StoreVersion.HIGH_LIMIT_V3_0.string() ); } @Rule @@ -260,14 +260,14 @@ public void shouldCommunicateWhatCausesInabilityToUpgrade() catch ( StoreUpgrader.UnexpectedUpgradingStoreVersionException e ) { // then - assertFalse( StoreVersions.isEnterpriseStoreVersion( version ) ); + assertFalse( StoreVersion.isEnterpriseStoreVersion( version ) ); File expectedFile = new File( workingDirectory, neostoreFilename ).getAbsoluteFile(); assertEquals( String.format( MESSAGE, expectedFile, version ), e.getMessage() ); } catch ( StoreUpgrader.UnexpectedUpgradingStoreFormatException e ) { // then - assertTrue( StoreVersions.isEnterpriseStoreVersion( version ) ); + assertTrue( StoreVersion.isEnterpriseStoreVersion( version ) ); assertEquals( String.format( StoreUpgrader.UnexpectedUpgradingStoreFormatException.MESSAGE, GraphDatabaseSettings.record_format.name() ), e.getMessage() ); } diff --git a/enterprise/kernel/src/main/java/org/neo4j/kernel/impl/store/format/highlimit/HighLimit.java b/enterprise/kernel/src/main/java/org/neo4j/kernel/impl/store/format/highlimit/HighLimit.java index aa39264b8262a..e5b0739de475f 100644 --- a/enterprise/kernel/src/main/java/org/neo4j/kernel/impl/store/format/highlimit/HighLimit.java +++ b/enterprise/kernel/src/main/java/org/neo4j/kernel/impl/store/format/highlimit/HighLimit.java @@ -23,7 +23,7 @@ import org.neo4j.kernel.impl.store.format.Capability; import org.neo4j.kernel.impl.store.format.RecordFormat; import org.neo4j.kernel.impl.store.format.RecordFormats; -import org.neo4j.kernel.impl.store.format.StoreVersions; +import org.neo4j.kernel.impl.store.format.StoreVersion; import org.neo4j.kernel.impl.store.format.standard.LabelTokenRecordFormat; import org.neo4j.kernel.impl.store.format.standard.PropertyKeyTokenRecordFormat; import org.neo4j.kernel.impl.store.format.standard.RelationshipTypeTokenRecordFormat; @@ -48,14 +48,13 @@ public class HighLimit extends BaseRecordFormats */ static final int DEFAULT_MAXIMUM_BITS_PER_ID = 50; + public static final String STORE_VERSION = StoreVersion.HIGH_LIMIT_V3_0.string(); public static final RecordFormats RECORD_FORMATS = new HighLimit(); - // Enterprise.HighLimit.Zero - public static final String STORE_VERSION = StoreVersions.HIGH_LIMIT_V3_0; public static final String NAME = "high_limit"; public HighLimit() { - super( STORE_VERSION, 6, Capability.DENSE_NODES, Capability.SCHEMA, Capability.LUCENE_5 ); + super( STORE_VERSION, 7, Capability.DENSE_NODES, Capability.SCHEMA, Capability.LUCENE_5 ); } @Override diff --git a/enterprise/neo4j-enterprise/src/test/java/org/neo4j/RecordFormatsGenerationTest.java b/enterprise/neo4j-enterprise/src/test/java/org/neo4j/RecordFormatsGenerationTest.java new file mode 100644 index 0000000000000..7062178f47d01 --- /dev/null +++ b/enterprise/neo4j-enterprise/src/test/java/org/neo4j/RecordFormatsGenerationTest.java @@ -0,0 +1,85 @@ +/* + * Copyright (c) 2002-2016 "Neo Technology," + * Network Engine for Objects in Lund AB [http://neotechnology.com] + * + * This file is part of Neo4j. + * + * Neo4j is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ +package org.neo4j; + +import org.junit.Test; + +import java.util.Arrays; +import java.util.List; + +import org.neo4j.kernel.impl.store.format.RecordFormatSelector; +import org.neo4j.kernel.impl.store.format.RecordFormats; +import org.neo4j.kernel.impl.store.format.StoreVersion; +import org.neo4j.kernel.impl.store.format.highlimit.HighLimit; +import org.neo4j.kernel.impl.store.format.standard.StandardV2_0; +import org.neo4j.kernel.impl.store.format.standard.StandardV2_1; +import org.neo4j.kernel.impl.store.format.standard.StandardV2_2; +import org.neo4j.kernel.impl.store.format.standard.StandardV2_3; +import org.neo4j.kernel.impl.store.format.standard.StandardV3_0; + +import static java.util.stream.Collectors.toList; +import static org.junit.Assert.assertEquals; + +public class RecordFormatsGenerationTest +{ + @Test + public void correctGenerations() + { + List expectedGenerations = Arrays.asList( + StandardV2_0.RECORD_FORMATS.generation(), + StandardV2_1.RECORD_FORMATS.generation(), + StandardV2_2.RECORD_FORMATS.generation(), + StandardV2_3.RECORD_FORMATS.generation(), + StandardV3_0.RECORD_FORMATS.generation(), + HighLimit.RECORD_FORMATS.generation() + ); + + assertEquals( expectedGenerations, distinct( allGenerations() ) ); + } + + @Test + public void uniqueGenerations() + { + assertEquals( allGenerations(), distinct( allGenerations() ) ); + } + + private static List allGenerations() + { + return allRecordFormats().stream() + .map( RecordFormats::generation ) + .sorted() + .collect( toList() ); + } + + private static List allRecordFormats() + { + return Arrays.stream( StoreVersion.values() ) + .map( StoreVersion::string ) + .map( RecordFormatSelector::selectForVersion ) + .collect( toList() ); + } + + private static List distinct( List integers ) + { + return integers.stream() + .distinct() + .collect( toList() ); + } +}