private File storeDir() { return directory.absolutePath(); } }
private GraphDatabaseService getGraphDatabaseService() { return getGraphDatabaseService( testDirectory.absolutePath() ); }
private File baseDir() { return rules.directory().absolutePath(); } }
@BeforeEach void setUp() throws Exception { homeDir = testDirectory.directory( "home-dir" ).toPath(); configDir = testDirectory.directory( "config-dir" ).toPath(); // Touch config configFile = configDir.resolve( "neo4j.conf" ); Files.createFile( configFile ); // To make sure files are resolved from the working directory originalUserDir = System.setProperty( "user.dir", testDirectory.absolutePath().getAbsolutePath() ); }
@Test void shouldGiveAClearErrorMessageIfTheDestinationsParentDirectoryIsAFile() throws IOException { Path archive = testDirectory.file( "the-archive.dump" ).toPath(); Path destination = Paths.get( testDirectory.absolutePath().getAbsolutePath(), "subdir", "the-destination" ); Files.write( destination.getParent(), new byte[0] ); FileSystemException exception = assertThrows( FileSystemException.class, () -> new Loader().load( archive, destination, destination ) ); assertEquals( destination.getParent().toString() + ": Not a directory", exception.getMessage() ); }
@Test void shouldGiveAClearErrorMessageIfTheDestinationsParentDirectoryDoesntExist() throws IOException { Path archive = testDirectory.file( "the-archive.dump" ).toPath(); Path destination = Paths.get( testDirectory.absolutePath().getAbsolutePath(), "subdir", "the-destination" ); NoSuchFileException noSuchFileException = assertThrows( NoSuchFileException.class, () -> new Loader().load( archive, destination, destination ) ); assertEquals( destination.getParent().toString(), noSuchFileException.getMessage() ); }
@Test void shouldGiveAClearErrorMessageIfTheTxLogsParentDirectoryDoesntExist() { Path archive = testDirectory.file( "the-archive.dump" ).toPath(); Path destination = testDirectory.file( "destination" ).toPath(); Path txLogsDestination = Paths.get( testDirectory.absolutePath().getAbsolutePath(), "subdir", "txLogs" ); NoSuchFileException noSuchFileException = assertThrows( NoSuchFileException.class, () -> new Loader().load( archive, destination, txLogsDestination ) ); assertEquals( txLogsDestination.getParent().toString(), noSuchFileException.getMessage() ); }
private Map<String,String> getPropertyPairs() { Map<String,String> properties = new HashMap<>(); properties.put( GraphDatabaseSettings.data_directory.name(), testDir.databaseDir().toString() ); properties.put( GraphDatabaseSettings.logs_directory.name(), testDir.databaseDir().toString() ); properties.put( LegacySslPolicyConfig.certificates_directory.name(), testDir.databaseDir().toString() ); properties.put( GraphDatabaseSettings.allow_upgrade.name(), Settings.TRUE ); HttpConnector http = new HttpConnector( "http", Encryption.NONE ); properties.put( http.type.name(), "HTTP" ); properties.put( http.listen_address.name(), "localhost:0" ); properties.put( http.enabled.name(), Settings.TRUE ); HttpConnector https = new HttpConnector( "https", Encryption.TLS ); properties.put( https.type.name(), "HTTP" ); properties.put( https.listen_address.name(), "localhost:0" ); properties.put( https.enabled.name(), Settings.TRUE ); BoltConnector bolt = new BoltConnector( DEFAULT_CONNECTOR_KEY ); properties.put( bolt.type.name(), "BOLT" ); properties.put( bolt.enabled.name(), "true" ); properties.put( bolt.listen_address.name(), "localhost:0" ); properties.put( GraphDatabaseSettings.database_path.name(), testDir.absolutePath().getAbsolutePath() ); return properties; }
private GraphDatabaseService newDb() { return factory.newEmbeddedDatabaseBuilder( storeDir.absolutePath() ).setConfig( GraphDatabaseSettings.default_schema_provider, schemaIndex.providerName() ).newGraphDatabase(); }
@Test public void shouldLogToStdOutByDefault() throws Exception { // given ServerBootstrapper serverBootstrapper = getServerBootstrapper(); File dir = homeDir.directory(); // when serverBootstrapper.start( dir, Optional.empty(), MapUtil.stringMap( database_path.name(), homeDir.absolutePath().getAbsolutePath() ) ); // then no exceptions are thrown and assertThat( getStdOut(), not( empty() ) ); assertTrue( !Files.exists( getUserLogFileLocation( dir ) ) ); // stop the server so that resources are released and test teardown isn't flaky serverBootstrapper.stop(); }
@Test void testThatPasses() throws Exception { CONTEXT.clear(); CONTEXT.setValue( TEST_DIR, testDirectory.absolutePath() ); profiler.profile(); someVeryExpensiveComputation(); } @Test
@Test public void shouldLogToFileWhenConfigured() throws Exception { // given ServerBootstrapper serverBootstrapper = getServerBootstrapper(); File dir = homeDir.directory(); // when serverBootstrapper.start( dir, Optional.empty(), MapUtil.stringMap( database_path.name(), homeDir.absolutePath().getAbsolutePath(), store_user_log_to_stdout.name(), "false" ) ); // then no exceptions are thrown and assertThat( getStdOut(), empty() ); assertTrue( Files.exists( getUserLogFileLocation( dir ) ) ); assertThat( readUserLogFile( dir ), not( empty() ) ); // stop the server so that resources are released and test teardown isn't flaky serverBootstrapper.stop(); }
@Test void testThatFails() throws Exception { CONTEXT.clear(); CONTEXT.setValue( TEST_DIR, testDirectory.absolutePath() ); profiler.profile(); someVeryExpensiveComputation(); fail( "This is exactly like that 'worst movie death scene ever' from the Turkish film Kareteci Kiz." ); }
@Test public void shouldRecoverCreationOfUniquenessConstraintFollowedByDeletionOfThatSameConstraint() throws Exception { // given createUniqueConstraint(); dropConstraints(); // when - perform recovery restart( snapshot( storeDir.absolutePath() ) ); // then - just make sure the constraint is gone try ( Transaction tx = db.beginTx() ) { assertFalse( db.schema().getConstraints( LABEL ).iterator().hasNext() ); tx.success(); } }
@Before public void start() throws IOException { jobScheduler = new ThreadPoolJobScheduler(); stores = BatchingNeoStores.batchingNeoStores( fileSystemRule.get(), directory.absolutePath(), format, CONFIG, NullLogService.getInstance(), AdditionalInitialIds.EMPTY, Config.defaults(), jobScheduler ); stores.createNew(); }
@Test public void schemaTransactionsShouldSurviveRecovery() throws Exception { // given File storeDir = testDirectory.absolutePath(); Process process = new CreateConstraintButDoNotShutDown().start( storeDir ); process.waitForSchemaTransactionCommitted(); SubProcess.kill( process ); // when GraphDatabaseService recoveredDatabase = new TestGraphDatabaseFactory().newEmbeddedDatabase( storeDir ); // then assertEquals(1, constraints( recoveredDatabase ).size()); assertEquals(1, indexes( recoveredDatabase ).size()); recoveredDatabase.shutdown(); }
@Test public void shouldNotDecideToAllocateDoubleRelationshipRecordUnitsonLargeAmountOfRelationshipsOnUnsupportedFormat() throws Exception { // given RecordFormats formats = LATEST_RECORD_FORMATS; try ( BatchingNeoStores stores = BatchingNeoStores.batchingNeoStoresWithExternalPageCache( storage.fileSystem(), storage.pageCache(), PageCacheTracer.NULL, storage.directory().absolutePath(), formats, DEFAULT, NullLogService.getInstance(), EMPTY, Config.defaults() ) ) { stores.createNew(); Estimates estimates = Inputs.knownEstimates( 0, DOUBLE_RELATIONSHIP_RECORD_UNIT_THRESHOLD << 1, 0, 0, 0, 0, 0 ); // when boolean doubleUnits = stores.determineDoubleRelationshipRecordUnits( estimates ); // then assertFalse( doubleUnits ); } }
@Test public void shouldNotDecideToAllocateDoubleRelationshipRecordUnitsonLowAmountOfRelationshipsOnSupportedFormat() throws Exception { // given RecordFormats formats = new ForcedSecondaryUnitRecordFormats( LATEST_RECORD_FORMATS ); try ( BatchingNeoStores stores = BatchingNeoStores.batchingNeoStoresWithExternalPageCache( storage.fileSystem(), storage.pageCache(), PageCacheTracer.NULL, storage.directory().absolutePath(), formats, DEFAULT, NullLogService.getInstance(), EMPTY, Config.defaults() ) ) { stores.createNew(); Estimates estimates = Inputs.knownEstimates( 0, DOUBLE_RELATIONSHIP_RECORD_UNIT_THRESHOLD >> 1, 0, 0, 0, 0, 0 ); // when boolean doubleUnits = stores.determineDoubleRelationshipRecordUnits( estimates ); // then assertFalse( doubleUnits ); } }
@Test public void shouldDecideToAllocateDoubleRelationshipRecordUnitsOnLargeAmountOfRelationshipsOnSupportedFormat() throws Exception { // given RecordFormats formats = new ForcedSecondaryUnitRecordFormats( LATEST_RECORD_FORMATS ); try ( PageCache pageCache = storage.pageCache(); BatchingNeoStores stores = BatchingNeoStores.batchingNeoStoresWithExternalPageCache( storage.fileSystem(), pageCache, PageCacheTracer.NULL, storage.directory().absolutePath(), formats, DEFAULT, NullLogService.getInstance(), EMPTY, Config.defaults() ) ) { stores.createNew(); Estimates estimates = Inputs.knownEstimates( 0, DOUBLE_RELATIONSHIP_RECORD_UNIT_THRESHOLD << 1, 0, 0, 0, 0, 0 ); // when boolean doubleUnits = stores.determineDoubleRelationshipRecordUnits( estimates ); // then assertTrue( doubleUnits ); } }
@Test public void shouldBeEmptyWhenFirstStarted() { // When File storeDir = testDir.absolutePath(); GraphDatabaseService db = new TestGraphDatabaseFactory().newEmbeddedDatabase( storeDir ); // Then try ( Transaction ignore = db.beginTx() ) { assertEquals( 0, count( db.getAllNodes() ) ); assertEquals( 0, count( db.getAllRelationships() ) ); assertEquals( 0, count( db.getAllRelationshipTypes() ) ); assertEquals( 0, count( db.getAllLabels() ) ); assertEquals( 0, count( db.getAllPropertyKeys() ) ); } db.shutdown(); } }