@Override public String asString() { return Exceptions.stringify( failure ); }
/** * Finds all threads and corresponding stack traces which can potentially cause the * {@link ExecutorService executor} to not terminate in {@link #AWAIT_TIMEOUT_MINUTES} minutes. * * @return thread dump as string. */ private static String allStackTraces() { return Thread.getAllStackTraces() .entrySet() .stream() .map( entry -> Exceptions.stringify( entry.getKey(), entry.getValue() ) ) .collect( joining() ); }
public static void printShortStackTrace( Throwable cause, int maxNumberOfStackLines ) { System.out.println( firstLinesOf( stringify( cause ), maxNumberOfStackLines + 1 ) ); }
private static void printLimitedStackTrace( PrintStream out, Throwable cause, int skip, int limit ) { synchronized ( out ) { String[] lines = stringify( cause ).split( lineSeparator() ); for ( String line : lines ) { if ( line.startsWith( "\tat " ) ) { if ( skip > 0 ) { skip--; } else if ( limit > 0 ) { limit--; out.println( line ); } else { break; } } else { out.println( line ); } } } }
private static KernelTransaction mockKernelTransaction() throws IndexNotFoundKernelException { SchemaRead schemaRead = mock( SchemaRead.class ); when( schemaRead.indexGetState( any( IndexReference.class ) ) ).thenReturn( InternalIndexState.FAILED ); when( schemaRead.indexGetFailure( any( IndexReference.class ) ) ).thenReturn( Exceptions.stringify( cause ) ); KernelTransaction kt = mock( KernelTransaction.class ); when( kt.tokenRead() ).thenReturn( mock( TokenRead.class ) ); when( kt.schemaRead() ).thenReturn( schemaRead ); when( kt.isTerminated() ).thenReturn( false ); when( kt.acquireStatement() ).thenReturn( mock( Statement.class ) ); return kt; } }
private <RECORD extends AbstractBaseRecord, REPORT extends ConsistencyReport> void dispatch( RecordType type, ProxyFactory<REPORT> factory, RECORD record, RecordCheck<RECORD, REPORT> checker ) { ReportInvocationHandler<RECORD,REPORT> handler = new ReportHandler<>( report, factory, type, records, record, monitor ); try { checker.check( record, handler, records ); } catch ( Exception e ) { // This is a rare event and exposing the stack trace is a good idea, otherwise we // can only see that something went wrong, not at all what. handler.report.error( type, record, "Failed to check record: " + stringify( e ), new Object[0] ); } handler.updateSummary(); }
private void assertUniquenessConstraintHolds( Collection<Value> data ) { try { verifyUniqueness( data ); } catch ( Throwable t ) { fail( "Unable to create uniqueness constraint for data: " + Strings.prettyPrint( data.toArray() ) + "\n" + Exceptions.stringify( t ) ); } }
@Test public void shouldThrowAnExceptionIfTheIndexHasFailed() throws IndexNotFoundKernelException { when( tokenRead.nodeLabel( anyString() ) ).thenReturn( 0 ); when( tokenRead.propertyKey( anyString() ) ).thenReturn( 0 ); when( schemaRead.index( anyInt(), any() ) ).thenReturn( anyIndex ); when( schemaRead.indexGetState( any( IndexReference.class ) ) ).thenReturn( FAILED ); when( schemaRead.indexGetFailure( any( IndexReference.class ) ) ).thenReturn( Exceptions.stringify( new Exception( "Kilroy was here" ) ) ); try { procedure.awaitIndexByPattern( ":Person(name)", TIMEOUT, TIME_UNIT ); fail( "Expected an exception" ); } catch ( ProcedureException e ) { assertThat( e.status(), is( Status.Schema.IndexCreationFailed ) ); assertThat( e.getMessage(), containsString( "Kilroy was here" ) ); } }
@Test void includeCauseOfFailure() throws IndexNotFoundKernelException { // given IndexDefinitionImpl indexDefinition = mockIndexDefinition(); KernelTransaction kernelTransaction = mockKernelTransaction(); SchemaImpl schema = new SchemaImpl( () -> kernelTransaction ); // when IllegalStateException e = assertThrows( IllegalStateException.class, () -> schema.awaitIndexOnline( indexDefinition, 1, TimeUnit.MINUTES ) ); // then assertThat( e.getMessage(), Matchers.containsString( Exceptions.stringify( cause ) ) ); }
@Override public String asString() { return Exceptions.stringify( failure ); }
public String errorData( Throwable cause ) { if ( cause == null ) { return NO_ERROR_DATA_AVAILABLE; } else { return printBase64Binary( Exceptions.stringify( cause ).getBytes( StandardCharsets.UTF_8 ) ) // Below replaceAll call inserts a line break every 100 characters .replaceAll( "(.{100})", "$1" + System.lineSeparator() ); } }
/** * Finds all threads and corresponding stack traces which can potentially cause the * {@link ExecutorService executor} to not terminate in {@link #AWAIT_TIMEOUT_MINUTES} minutes. * * @return thread dump as string. */ private static String allStackTraces() { return Thread.getAllStackTraces() .entrySet() .stream() .map( entry -> Exceptions.stringify( entry.getKey(), entry.getValue() ) ) .collect( joining() ); }
public static void printShortStackTrace( Throwable cause, int maxNumberOfStackLines ) { System.out.println( firstLinesOf( stringify( cause ), maxNumberOfStackLines + 1 ) ); }
private static void printLimitedStackTrace( PrintStream out, Throwable cause, int skip, int limit ) { synchronized ( out ) { String[] lines = stringify( cause ).split( lineSeparator() ); for ( String line : lines ) { if ( line.startsWith( "\tat " ) ) { if ( skip > 0 ) { skip--; } else if ( limit > 0 ) { limit--; out.println( line ); } else { break; } } else { out.println( line ); } } } }
public Neo4jError translate( Throwable any ) { for( Throwable cause = any; cause != null; cause = cause.getCause() ) { if ( cause instanceof Status.HasStatus ) { return new Neo4jError( ((Status.HasStatus) cause).status(), any.getMessage() ); } } // In this case, an error has "slipped out", and we don't have a good way to handle it. This indicates // a buggy code path, and we need to try to convince whoever ends up here to tell us about it. // TODO: Perhaps move this whole block to somewhere more sensible? String reference = UUID.randomUUID().toString(); // Log unknown errors. userLog.error( String.format( "Client triggered unexpected error. Help us fix this error by emailing the " + "following report to issues@neotechnology.com: %n%s", generateReport( any, reference ) ), any ); internalLog.error( String.format( "Client triggered unexpected error, reference %s.", reference), any ); return new Neo4jError( Status.General.UnknownFailure, String.format( "An unexpected failure occurred, see details in the database " + "logs, reference number %s.%n%s", reference, Exceptions.stringify( any ) ) ); }
private static void copyStore(String sourceDir, String targetDir, Set<String> ignoreRelTypes, Set<String> ignoreProperties, Set<String> ignoreLabels, Set<String> deleteNodesWithLabels, boolean stableNodeIds) throws Exception { final File target = new File(targetDir); final File source = new File(sourceDir); if (target.exists()) { // FileUtils.deleteRecursively(target); throw new IllegalArgumentException("Target Directory already exists "+target); } if (!source.exists()) throw new IllegalArgumentException("Source Database does not exist " + source); Pair<Long, Long> highestIds = getHighestNodeId(source); String pageCacheSize = System.getProperty("dbms.pagecache.memory","2G"); BatchInserter targetDb = BatchInserters.inserter(target, MapUtil.stringMap("dbms.pagecache.memory", pageCacheSize)); BatchInserter sourceDb = BatchInserters.inserter(source, MapUtil.stringMap("dbms.pagecache.memory", System.getProperty("dbms.pagecache.memory.source",pageCacheSize))); Flusher flusher = getFlusher(sourceDb); logs = new PrintWriter(new FileWriter(new File(target, "store-copy.log"))); PrimitiveLongLongMap copiedNodeIds = copyNodes(sourceDb, targetDb, ignoreProperties, ignoreLabels, deleteNodesWithLabels, highestIds.first(),flusher, stableNodeIds); copyRelationships(sourceDb, targetDb, ignoreRelTypes, ignoreProperties, copiedNodeIds, highestIds.other(), flusher); targetDb.shutdown(); try { sourceDb.shutdown(); } catch (Exception e) { logs.append(String.format("Noncritical error closing the source database:%n%s", Exceptions.stringify(e))); } logs.close(); if (stableNodeIds) copyIndex(source, target); }