@Test public void shouldWriteToInternalDiagnosticsLog() throws Exception { // Given new TestGraphDatabaseFactory().newEmbeddedDatabaseBuilder( testDir.databaseDir() ) .setConfig( GraphDatabaseSettings.logs_directory, testDir.directory("logs").getAbsolutePath() ) .newGraphDatabase().shutdown(); File internalLog = new File( testDir.directory( "logs" ), INTERNAL_LOG_FILE ); // Then assertThat( internalLog.isFile(), is( true ) ); assertThat( internalLog.length(), greaterThan( 0L ) ); assertEquals( 1, countOccurrences( internalLog, "Database graph.db is ready." ) ); assertEquals( 2, countOccurrences( internalLog, "Database graph.db is unavailable." ) ); }
@Test public void shouldHandleFixturesWithSyntaxErrorsGracefully() throws Exception { // Given two files in the root folder File targetFolder = testDir.directory(); FileUtils.writeToFile( new File( targetFolder, "fixture1.cyp" ), "this is not a valid cypher statement", false ); // When try ( ServerControls ignore = getServerBuilder( targetFolder ) .withFixture( targetFolder ).newServer() ) { fail("Should have thrown exception"); } catch ( RuntimeException e ) { assertThat( e.getMessage(), equalTo( "Invalid input 't': expected <init> (line 1, column 1 (offset: 0))" + lineSeparator() + "\"this is not a valid cypher statement\"" + lineSeparator() + " ^" ) ); } }
@Test public void shouldLoadThirdPartyJaxRsClasses() throws Exception { server = CommunityServerBuilder.serverOnRandomPorts() .withThirdPartyJaxRsPackage( "org.dummy.web.service", DummyThirdPartyWebService.DUMMY_WEB_SERVICE_MOUNT_POINT ) .usingDataDir( folder.directory( name.getMethodName() ).getAbsolutePath() ) .build(); server.start(); URI thirdPartyServiceUri = new URI( server.baseUri() .toString() + DummyThirdPartyWebService.DUMMY_WEB_SERVICE_MOUNT_POINT ).normalize(); String response = CLIENT.resource( thirdPartyServiceUri.toString() ) .get( String.class ); assertEquals( "hello", response ); // Assert that extensions gets initialized int nodesCreated = createSimpleDatabase( server.getDatabase().getGraph() ); thirdPartyServiceUri = new URI( server.baseUri() .toString() + DummyThirdPartyWebService.DUMMY_WEB_SERVICE_MOUNT_POINT + "/inject-test" ).normalize(); response = CLIENT.resource( thirdPartyServiceUri.toString() ) .get( String.class ); assertEquals( String.valueOf( nodesCreated ), response ); }
@Test public void shouldNotWriteDebugToInternalDiagnosticsLogByDefault() throws Exception { // Given GraphDatabaseService db = new TestGraphDatabaseFactory().newEmbeddedDatabaseBuilder( testDir.storeDir() ) .setConfig( GraphDatabaseSettings.logs_directory, testDir.directory("logs").getAbsolutePath() ) .newGraphDatabase(); // When LogService logService = ((GraphDatabaseAPI) db).getDependencyResolver().resolveDependency( LogService.class ); logService.getInternalLog( getClass() ).debug( "A debug entry" ); db.shutdown(); File internalLog = new File( testDir.directory( "logs" ), INTERNAL_LOG_FILE ); // Then assertThat( internalLog.isFile(), is( true ) ); assertThat( internalLog.length(), greaterThan( 0L ) ); assertEquals( 0, countOccurrences( internalLog, "A debug entry" ) ); }
@Test public void consistencyCheckerLogUseSystemTimezoneIfConfigurable() throws Exception { TimeZone defaultTimeZone = TimeZone.getDefault(); try { ConsistencyCheckService service = mock( ConsistencyCheckService.class ); Mockito.when( service.runFullConsistencyCheck( any( DatabaseLayout.class ), any( Config.class ), any( ProgressMonitorFactory.class ), any( LogProvider.class ), any( FileSystemAbstraction.class ), eq( false ), any( ConsistencyFlags.class ) ) ) .then( invocationOnMock -> { LogProvider provider = invocationOnMock.getArgument( 3 ); provider.getLog( "test" ).info( "testMessage" ); return ConsistencyCheckService.Result.success( new File( StringUtils.EMPTY ) ); } ); File storeDir = testDirectory.directory(); File configFile = testDirectory.file( Config.DEFAULT_CONFIG_FILE_NAME ); Properties properties = new Properties(); properties.setProperty( GraphDatabaseSettings.db_timezone.name(), LogTimeZone.SYSTEM.name() ); properties.store( new FileWriter( configFile ), null ); String[] args = {storeDir.getPath(), "-config", configFile.getPath()}; checkLogRecordTimeZone( service, args, 5, "+0500" ); checkLogRecordTimeZone( service, args, -5, "-0500" ); } finally { TimeZone.setDefault( defaultTimeZone ); } }
@Test public void shouldEnableConsoleServiceByDefault() throws IOException { // Given server = serverOnRandomPorts() .usingDataDir( folder.directory( name.getMethodName() ).getAbsolutePath() ) .build(); server.start(); // When & then assertEquals( 200, new RestRequest().get( server.baseUri().toString() + "db/manage/server/console" ).getStatus() ); }
@Test public void shouldBeAbleToRecoverBrokenStoreWithLogsInSeparateAbsoluteLocation() throws Exception { File customTransactionLogsLocation = testDirectory.directory( "tx-logs" ); Config config = Config.defaults( logical_logs_location, customTransactionLogsLocation.getAbsolutePath() ); recoverBrokenStoreWithConfig( config ); }
@BeforeClass public static void startGlobalInserter() throws IOException { // Global inserter can be used in tests which simply want to verify "local" behaviour, // e.g. create a node with some properties and read them back. globalInserter = BatchInserters.inserter( globalTestDirectory.directory( "global" ), fileSystemRule.get(), stringMap() ); }
@Test public void shouldFailIfFileDoesNotExist() { // given File missingFile = new File( directory.directory(), "missing-file" ); PageCache pageCache = pageCacheRule.getPageCache( fileSystemRule.get() ); StoreVersionCheck storeVersionCheck = new StoreVersionCheck( pageCache ); // when StoreVersionCheck.Result result = storeVersionCheck.hasVersion( missingFile, "version" ); // then assertFalse( result.outcome.isSuccessful() ); assertEquals( StoreVersionCheck.Result.Outcome.missingStoreFile, result.outcome ); assertNull( result.actualVersion ); }
@Test public void copiesDatabaseFromOldLocationToNewLocation() throws Exception { File home = testDir.directory( "home" ); File from = provideStoreDirectory(); File destination = new File( new File( new File( home, "data" ), "databases" ), "bar" ); String[] arguments = {"--mode=database", "--database=bar", "--from=" + from.getAbsolutePath()}; DatabaseImporter importer = new DatabaseImporter( Args.parse( arguments ), getConfigWith( home, "bar" ), new NullOutsideWorld() ); assertThat( destination, not( isExistingDatabase() ) ); importer.doImport(); assertThat( destination, isExistingDatabase() ); }
private File writeToFile( byte[] header, String data, Charset charset ) throws IOException { File file = new File( directory.directory(), "text-" + charset.name() ); try ( OutputStream out = new FileOutputStream( file ); Writer writer = new OutputStreamWriter( out, charset ) ) { out.write( header ); writer.append( data ); } return file; }
@Test public void shouldGenerateWADLWhenExplicitlyEnabledInConfig() throws IOException { server = serverOnRandomPorts().withProperty( ServerSettings.wadl_enabled.name(), "true" ) .usingDataDir( folder.directory( name.getMethodName() ).getAbsolutePath() ) .build(); server.start(); JaxRsResponse response = new RestRequest().get( server.baseUri().toString() + "application.wadl", MediaType.WILDCARD_TYPE ); assertEquals( 200, response.getStatus() ); assertEquals( "application/vnd.sun.wadl+xml", response.getHeaders().get( "Content-Type" ).iterator().next() ); assertThat( response.getEntity(), containsString( "<application xmlns=\"http://wadl.dev.java" + ".net/2009/02\">" ) ); }
@Test public void shouldLaunchAServerInSpecifiedDirectory() { // Given File workDir = testDir.directory( "specific" ); // When try ( ServerControls server = getTestServerBuilder( workDir ).newServer() ) { // Then assertThat( HTTP.GET( server.httpURI().toString() ).status(), equalTo( 200 ) ); assertThat( workDir.list().length, equalTo( 1 ) ); } // And after it's been closed, it should've cleaned up after itself. assertThat( Arrays.toString( workDir.list() ), workDir.list().length, equalTo( 0 ) ); }
@Before public void setUp() { File folder = testDir.directory( "folder" ); indexStorage = new PartitionedIndexStorage( directoryFactory, fileSystemRule.get(), folder ); index = LuceneSchemaIndexBuilder.create( descriptor, Config.defaults() ) .withIndexStorage( indexStorage ) .build(); schemaDescriptor = descriptor.schema(); }
@Test public void shouldFailIfTheStoreInNotConsistent() throws Exception { // given breakNodeStore(); Date timestamp = new Date(); ConsistencyCheckService service = new ConsistencyCheckService( timestamp ); String logsDir = testDirectory.directory().getPath(); Config configuration = Config.defaults( settings( GraphDatabaseSettings.logs_directory.name(), logsDir ) ); // when ConsistencyCheckService.Result result = runFullConsistencyCheck( service, configuration ); // then assertFalse( result.isSuccessful() ); String reportFile = format( "inconsistencies-%s.report", new SimpleDateFormat( "yyyy-MM-dd.HH.mm.ss" ).format( timestamp ) ); assertEquals( new File( logsDir, reportFile ), result.reportFile() ); assertTrue( "Inconsistency report file not generated", result.reportFile().exists() ); }