-
Notifications
You must be signed in to change notification settings - Fork 2.3k
/
RecordFormatsMigrationIT.java
180 lines (158 loc) · 6.3 KB
/
RecordFormatsMigrationIT.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
/*
* Copyright (c) 2002-2018 "Neo4j,"
* Neo4j Sweden AB [http://neo4j.com]
*
* This file is part of Neo4j Enterprise Edition. The included source
* code can be redistributed and/or modified under the terms of the
* GNU AFFERO GENERAL PUBLIC LICENSE Version 3
* (http://www.fsf.org/licensing/licenses/agpl-3.0.html) with the
* Commons Clause, as found in the associated LICENSE.txt file.
*
* 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.
*
* Neo4j object code can be licensed independently from the source
* under separate terms from the AGPL. Inquiries can be directed to:
* licensing@neo4j.com
*
* More information is also available at:
* https://neo4j.com/licensing/
*/
package org.neo4j.upgrade;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.RuleChain;
import java.util.function.Consumer;
import org.neo4j.graphdb.GraphDatabaseService;
import org.neo4j.graphdb.Label;
import org.neo4j.graphdb.Node;
import org.neo4j.graphdb.Transaction;
import org.neo4j.graphdb.factory.GraphDatabaseSettings;
import org.neo4j.helpers.Exceptions;
import org.neo4j.io.pagecache.PageCache;
import org.neo4j.kernel.configuration.Config;
import org.neo4j.kernel.configuration.Settings;
import org.neo4j.kernel.impl.enterprise.configuration.OnlineBackupSettings;
import org.neo4j.kernel.impl.pagecache.ConfigurableStandalonePageCacheFactory;
import org.neo4j.kernel.impl.store.format.RecordFormatSelector;
import org.neo4j.kernel.impl.store.format.RecordFormats;
import org.neo4j.kernel.impl.store.format.highlimit.HighLimit;
import org.neo4j.kernel.impl.store.format.highlimit.v300.HighLimitV3_0_0;
import org.neo4j.kernel.impl.store.format.standard.Standard;
import org.neo4j.kernel.impl.storemigration.StoreUpgrader.UnexpectedUpgradingStoreFormatException;
import org.neo4j.logging.NullLogProvider;
import org.neo4j.test.TestGraphDatabaseFactory;
import org.neo4j.test.rule.TestDirectory;
import org.neo4j.test.rule.fs.DefaultFileSystemRule;
import static org.hamcrest.Matchers.instanceOf;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.fail;
public class RecordFormatsMigrationIT
{
private static final Label LABEL = Label.label( "Centipede" );
private static final String PROPERTY = "legs";
private static final int VALUE = 42;
private final DefaultFileSystemRule fileSystemRule = new DefaultFileSystemRule();
private final TestDirectory testDirectory = TestDirectory.testDirectory( fileSystemRule.get() );
@Rule
public RuleChain ruleChain = RuleChain.outerRule( testDirectory ).around( fileSystemRule );
@Test
public void migrateLatestStandardToLatestHighLimit()
{
executeAndStopDb( startStandardFormatDb(), RecordFormatsMigrationIT::createNode );
assertLatestStandardStore();
executeAndStopDb( startHighLimitFormatDb(), RecordFormatsMigrationIT::assertNodeExists );
assertLatestHighLimitStore();
}
@Test
public void migrateHighLimitV3_0ToLatestHighLimit()
{
executeAndStopDb( startDb( HighLimitV3_0_0.NAME ), RecordFormatsMigrationIT::createNode );
assertStoreFormat( HighLimitV3_0_0.RECORD_FORMATS );
executeAndStopDb( startHighLimitFormatDb(), RecordFormatsMigrationIT::assertNodeExists );
assertLatestHighLimitStore();
}
@Test
public void migrateHighLimitToStandard()
{
executeAndStopDb( startHighLimitFormatDb(), RecordFormatsMigrationIT::createNode );
assertLatestHighLimitStore();
try
{
startStandardFormatDb();
fail( "Should not be possible to downgrade" );
}
catch ( Exception e )
{
assertThat( Exceptions.rootCause( e ), instanceOf( UnexpectedUpgradingStoreFormatException.class ) );
}
assertLatestHighLimitStore();
}
private static void createNode( GraphDatabaseService db )
{
try ( Transaction tx = db.beginTx() )
{
Node start = db.createNode( LABEL );
start.setProperty( PROPERTY, VALUE );
tx.success();
}
}
private static void assertNodeExists( GraphDatabaseService db )
{
try ( Transaction tx = db.beginTx() )
{
assertNotNull( db.findNode( LABEL, PROPERTY, VALUE ) );
tx.success();
}
}
private GraphDatabaseService startStandardFormatDb()
{
return startDb( Standard.LATEST_NAME );
}
private GraphDatabaseService startHighLimitFormatDb()
{
return startDb( HighLimit.NAME );
}
private GraphDatabaseService startDb( String recordFormatName )
{
return new TestGraphDatabaseFactory().newEmbeddedDatabaseBuilder( testDirectory.directory() )
.setConfig( GraphDatabaseSettings.allow_upgrade, Settings.TRUE )
.setConfig( GraphDatabaseSettings.record_format, recordFormatName )
.setConfig( OnlineBackupSettings.online_backup_enabled, Settings.FALSE )
.newGraphDatabase();
}
private void assertLatestStandardStore()
{
assertStoreFormat( Standard.LATEST_RECORD_FORMATS );
}
private void assertLatestHighLimitStore()
{
assertStoreFormat( HighLimit.RECORD_FORMATS );
}
private void assertStoreFormat( RecordFormats expected )
{
Config config = Config.defaults( GraphDatabaseSettings.pagecache_memory, "8m" );
try ( PageCache pageCache = ConfigurableStandalonePageCacheFactory.createPageCache( fileSystemRule.get(), config ) )
{
RecordFormats actual = RecordFormatSelector.selectForStoreOrConfig( config, testDirectory.graphDbDir(),
fileSystemRule, pageCache, NullLogProvider.getInstance() );
assertNotNull( actual );
assertEquals( expected.storeVersion(), actual.storeVersion() );
}
}
private static void executeAndStopDb( GraphDatabaseService db, Consumer<GraphDatabaseService> action )
{
try
{
action.accept( db );
}
finally
{
db.shutdown();
}
}
}