Skip to content

Commit

Permalink
Revert the change to query logging format
Browse files Browse the repository at this point in the history
  • Loading branch information
Zhen Li authored and lutovich committed Jul 26, 2018
1 parent e9791e0 commit 1b1090d
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
import static org.mockito.Mockito.mock;
import static org.neo4j.bolt.v3.messaging.decoder.HelloMessageDecoderTest.assertOriginalMessageEqualsToDecoded;
import static org.neo4j.values.storable.Values.longValue;
import static org.neo4j.values.storable.Values.stringValue;
import static org.neo4j.values.virtual.MapValue.EMPTY;

class BeginMessageDecoderTest
{
Expand All @@ -54,7 +54,7 @@ void shouldReturnConnectResponseHandler()
void shouldDecodeBeginMessage() throws Exception
{
BeginMessage originalMessage =
new BeginMessage( VirtualValues.map( new String[]{"tx_metadata", "tx_timeout"}, new AnyValue[]{stringValue( "R" ), longValue( 10000 )} ) );
new BeginMessage( VirtualValues.map( new String[]{"tx_metadata", "tx_timeout"}, new AnyValue[]{EMPTY, longValue( 10000 )} ) );
assertOriginalMessageEqualsToDecoded( originalMessage, decoder );
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@
import org.neo4j.bolt.v3.messaging.request.RunMessage;
import org.neo4j.bolt.v3.runtime.FailedState;
import org.neo4j.bolt.v3.runtime.ReadyState;
import org.neo4j.bolt.v3.runtime.StreamingState;
import org.neo4j.bolt.v3.runtime.TransactionReadyState;
import org.neo4j.bolt.v3.runtime.TransactionStreamingState;
import org.neo4j.kernel.api.exceptions.Status;

import static org.hamcrest.CoreMatchers.instanceOf;
Expand Down Expand Up @@ -76,7 +76,7 @@ void shouldMoveToStreamingOnRun_succ() throws Throwable
assertTrue( response.hasMetadata( "fields" ) );
assertTrue( response.hasMetadata( "result_available_after" ) );
assertFalse( response.hasMetadata( "tx_id" ) );
assertThat( machine.state(), instanceOf( StreamingState.class ) );
assertThat( machine.state(), instanceOf( TransactionStreamingState.class ) );
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,10 @@
package org.neo4j.kernel.impl.query;

import java.util.Collection;
import java.util.Collections;
import java.util.Map;

import org.neo4j.helpers.Strings;
import org.neo4j.kernel.api.query.QuerySnapshot;
import org.neo4j.values.AnyValue;
import org.neo4j.values.utils.PrettyPrinter;
Expand Down Expand Up @@ -98,6 +100,49 @@ static String formatAnyValue( AnyValue value )

static void formatMap( StringBuilder result, Map<String,Object> params )
{
result.append( params.toString() );
formatMap( result, params, Collections.emptySet() );
}

static void formatMap( StringBuilder result, Map<String, Object> params, Collection<String> obfuscate )
{
result.append( '{' );
if ( params != null )
{
String sep = "";
for ( Map.Entry<String,Object> entry : params.entrySet() )
{
result
.append( sep )
.append( entry.getKey() )
.append( ": " );

if ( obfuscate.contains( entry.getKey() ) )
{
result.append( "******" );
}
else
{
formatValue( result, entry.getValue() );
}
sep = ", ";
}
}
result.append( "}" );
}

private static void formatValue( StringBuilder result, Object value )
{
if ( value instanceof Map<?,?> )
{
formatMap( result, (Map<String, Object>) value, Collections.emptySet() );
}
else if ( value instanceof String )
{
result.append( '\'' ).append( value ).append( '\'' );
}
else
{
result.append( Strings.prettyPrint( value ) );
}
}
}

0 comments on commit 1b1090d

Please sign in to comment.