Skip to content

Commit

Permalink
Ensure that edition is available from shell dbinfo
Browse files Browse the repository at this point in the history
This adds tests that verify that you can get the edition of the database
using neo4j-shell. It also fixes an issue where simple output on local
databases in shell would not be printed.
  • Loading branch information
thobe committed Dec 2, 2015
1 parent 76d5b09 commit 09f4d86
Show file tree
Hide file tree
Showing 6 changed files with 83 additions and 11 deletions.
20 changes: 19 additions & 1 deletion community/shell/src/main/java/org/neo4j/shell/ShellLobby.java
Expand Up @@ -28,6 +28,7 @@
import org.neo4j.shell.impl.RemoteClient;
import org.neo4j.shell.impl.RmiLocation;
import org.neo4j.shell.impl.SameJvmClient;
import org.neo4j.shell.impl.SystemOutput;

/**
* A convenience class for creating servers clients as well as finding remote
Expand Down Expand Up @@ -95,7 +96,24 @@ public static ShellClient newClient( ShellServer server ) throws ShellException
public static ShellClient newClient( ShellServer server, Map<String, Serializable> initialSession,
CtrlCHandler signalHandler ) throws ShellException
{
return new SameJvmClient( initialSession, server, signalHandler );
return newClient( server, initialSession, new SystemOutput(), signalHandler );
}

/**
* Creates a client and "starts" it, i.e. grabs the console prompt.
* @param server the server (in the same JVM) which the client will
* communicate with.
* @param initialSession the initial session variables the shell will have,
* in addition to those provided by the server initially.
* @param output the output to write to.
* @param signalHandler the ctrl-c handler to use
* @throws ShellException if the execution fails
* @return the new shell client.
*/
public static ShellClient newClient( ShellServer server, Map<String, Serializable> initialSession,
Output output, CtrlCHandler signalHandler ) throws ShellException
{
return new SameJvmClient( initialSession, server, output, signalHandler );
}

/**
Expand Down
Expand Up @@ -41,6 +41,7 @@
import org.neo4j.shell.impl.RmiLocation;
import org.neo4j.shell.impl.ShellBootstrap;
import org.neo4j.shell.impl.SimpleAppServer;
import org.neo4j.shell.impl.SystemOutput;
import org.neo4j.shell.kernel.GraphDatabaseShellServer;

import static org.neo4j.io.fs.FileUtils.newBufferedFileReader;
Expand Down Expand Up @@ -299,7 +300,8 @@ public void run()
{
out.println( "NOTE: Local Neo4j graph database service at '" + dbPath + "'" );
}
ShellClient client = ShellLobby.newClient( server, getSessionVariablesFromArgs( args ), signalHandler );
ShellClient client = ShellLobby.newClient( server, getSessionVariablesFromArgs( args ),
new SystemOutput( out ), signalHandler );
grabPromptOrJustExecuteCommand( client, args );

shutdownIfNecessary( server );
Expand Down
Expand Up @@ -19,11 +19,11 @@
*/
package org.neo4j.shell.impl;

import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.io.Serializable;
import java.io.UnsupportedEncodingException;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;

import org.neo4j.shell.Output;

Expand All @@ -35,13 +35,14 @@ public class SystemOutput implements Output
{
private PrintWriter out;

public SystemOutput() {
try {
out = new PrintWriter(new OutputStreamWriter(System.out,"UTF-8"));
} catch (UnsupportedEncodingException e) {
System.err.println("Unsupported encoding UTF-8, using "+Charset.defaultCharset()+", error: "+e.getMessage());
out = new PrintWriter(new OutputStreamWriter(System.out, Charset.defaultCharset()));
}
public SystemOutput()
{
this( System.out );
}

public SystemOutput( OutputStream out )
{
this.out = new PrintWriter( new OutputStreamWriter( out, StandardCharsets.UTF_8 ) );
}

public void print( Serializable object )
Expand Down
19 changes: 19 additions & 0 deletions community/shell/src/test/java/org/neo4j/shell/StartClientTest.java
Expand Up @@ -174,6 +174,25 @@ protected GraphDatabaseShellServer getGraphDatabaseShellServer( String dbPath, b
verify( databaseShellServer ).shutdown();
}

@Test
public void shouldReportEditionThroughDbInfoApp() throws Exception
{
// given
ByteArrayOutputStream out = new ByteArrayOutputStream();
ByteArrayOutputStream err = new ByteArrayOutputStream();
CtrlCHandler ctrlCHandler = mock( CtrlCHandler.class );
StartClient client = new StartClient(
new PrintStream( out ), new PrintStream( err ) );

// when
client.start( new String[]{"-path", db.getGraphDatabaseAPI().getStoreDir(),
"-c", "dbinfo -g Configuration edition"}, ctrlCHandler );

// then
assertEquals( 0, err.size() );
assertThat( out.toString(), containsString( "\"edition\": \"Community\"" ) );
}

@Test
public void shouldPrintVersionAndExit() throws Exception
{
Expand Down
6 changes: 6 additions & 0 deletions enterprise/kernel/pom.xml
Expand Up @@ -143,6 +143,12 @@
<version>${project.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.neo4j</groupId>
<artifactId>neo4j-jmx</artifactId>
<version>${project.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.neo4j</groupId>
<artifactId>neo4j-io</artifactId>
Expand Down
Expand Up @@ -22,15 +22,23 @@
import java.io.ByteArrayOutputStream;
import java.io.PrintStream;

import org.junit.Rule;
import org.junit.Test;

import org.neo4j.test.TargetDirectory;

import static org.hamcrest.CoreMatchers.containsString;
import static org.hamcrest.CoreMatchers.startsWith;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertThat;
import static org.mockito.Mockito.mock;
import static org.neo4j.test.TargetDirectory.testDirForTest;

public class EnterpriseVersionTest
{
@Rule
public final TargetDirectory.TestDirectory dir = testDirForTest( EnterpriseVersionTest.class );

@Test
public void shouldPrintVersionAndExit() throws Exception
{
Expand All @@ -48,4 +56,22 @@ public void shouldPrintVersionAndExit() throws Exception
String version = out.toString();
assertThat( version, startsWith( "Neo4j Enterprise, version " ) );
}

@Test
public void shouldReportEditionThroughDbInfoApp() throws Exception
{
// given
ByteArrayOutputStream out = new ByteArrayOutputStream();
ByteArrayOutputStream err = new ByteArrayOutputStream();
CtrlCHandler ctrlCHandler = mock( CtrlCHandler.class );
StartClient client = new StartClient( new PrintStream( out ), new PrintStream( err ) );

// when
client.start( new String[]{"-path", dir.absolutePath(),
"-c", "dbinfo -g Configuration edition"}, ctrlCHandler );

// then
assertEquals( 0, err.size() );
assertThat( out.toString(), containsString( "\"edition\": \"Enterprise\"" ) );
}
}

0 comments on commit 09f4d86

Please sign in to comment.