Skip to content

Commit

Permalink
Migrating tests to testkit part 3 (neo4j#840)
Browse files Browse the repository at this point in the history
Adding support for supportsMultiDB call.

And exporting the following tests to testkit:
- shouldServerWithBoltV4SupportMultiDb -> test_should_successfully_check_if_support_for_multi_db_is_available
- shouldServerWithBoltV3NotSupportMultiDb -> test_should_successfully_check_if_support_for_multi_db_is_available

Removing redundant scripts
  • Loading branch information
injectives authored Mar 2, 2021
1 parent 0c7c3c5 commit 1de4b2d
Show file tree
Hide file tree
Showing 9 changed files with 100 additions and 143 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@

import java.io.IOException;
import java.net.URI;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.concurrent.TimeUnit;
Expand All @@ -48,10 +47,8 @@
import org.neo4j.driver.internal.cluster.RoutingSettings;
import org.neo4j.driver.internal.retry.RetrySettings;
import org.neo4j.driver.internal.security.SecurityPlanImpl;
import org.neo4j.driver.internal.util.DriverFactoryWithClock;
import org.neo4j.driver.internal.util.DriverFactoryWithFixedRetryLogic;
import org.neo4j.driver.internal.util.Futures;
import org.neo4j.driver.internal.util.SleeplessClock;
import org.neo4j.driver.net.ServerAddress;
import org.neo4j.driver.net.ServerAddressResolver;
import org.neo4j.driver.reactive.RxResult;
Expand All @@ -63,9 +60,7 @@
import static org.hamcrest.core.IsEqual.equalTo;
import static org.hamcrest.junit.MatcherAssert.assertThat;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
Expand Down Expand Up @@ -229,6 +224,8 @@ void shouldFailInitialDiscoveryWhenConfiguredResolverThrows()
verify( resolver ).resolve( ServerAddress.of( "my.server.com", 9001 ) );
}

// general error reporting and handling should be improved before this can be moved to testkit
// also, backend closes socket on general errors and it negatively impacts testkit's teardown process
@Test
void useSessionAfterDriverIsClosed() throws Exception
{
Expand Down Expand Up @@ -256,45 +253,6 @@ void useSessionAfterDriverIsClosed() throws Exception
}
}

@Test
void shouldServerWithBoltV4SupportMultiDb() throws Throwable
{
StubServer server = stubController.startStub( "support_multidb_v4.script", 9001 );
try ( Driver driver = GraphDatabase.driver( "neo4j://localhost:9001", INSECURE_CONFIG ) )
{
assertTrue( driver.supportsMultiDb() );
}
finally
{
assertEquals( 0, server.exitStatus() );
}
}

@Test
void shouldServerWithBoltV3NotSupportMultiDb() throws Throwable
{
StubServer server = stubController.startStub( "support_multidb_v3.script", 9001 );
try ( Driver driver = GraphDatabase.driver( "neo4j://localhost:9001", INSECURE_CONFIG ) )
{
assertFalse( driver.supportsMultiDb() );
}
finally
{
assertEquals( 0, server.exitStatus() );
}
}

private static Driver newDriverWithSleeplessClock( String uriString, Config config )
{
DriverFactory driverFactory = new DriverFactoryWithClock( new SleeplessClock() );
return newDriver( uriString, driverFactory, config );
}

private static Driver newDriverWithSleeplessClock( String uriString )
{
return newDriverWithSleeplessClock( uriString, INSECURE_CONFIG );
}

private static Driver newDriverWithFixedRetries( String uriString, int retries )
{
DriverFactory driverFactory = new DriverFactoryWithFixedRetryLogic( retries );
Expand All @@ -318,20 +276,6 @@ private static TransactionWork<List<Record>> queryWork( final String query, fina
};
}

private static List<String> readStrings( final String query, Session session )
{
return session.readTransaction( tx ->
{
List<Record> records = tx.run( query ).list();
List<String> names = new ArrayList<>( records.size() );
for ( Record record : records )
{
names.add( record.get( 0 ).asString() );
}
return names;
} );
}

static class PortBasedServerAddressComparator implements Comparator<ServerAddress>
{
@Override
Expand Down

This file was deleted.

16 changes: 0 additions & 16 deletions driver/src/test/resources/get_routing_table_with_context.script

This file was deleted.

17 changes: 0 additions & 17 deletions driver/src/test/resources/routing_context_in_hello_neo4j.script

This file was deleted.

13 changes: 0 additions & 13 deletions driver/src/test/resources/write_server_v3_write_tx.script

This file was deleted.

13 changes: 0 additions & 13 deletions driver/src/test/resources/write_tx_with_bookmarks.script

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/*
* Copyright (c) "Neo4j"
* Neo4j Sweden AB [http://neo4j.com]
*
* This file is part of Neo4j.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package neo4j.org.testkit.backend.messages.requests;

import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import neo4j.org.testkit.backend.TestkitState;
import neo4j.org.testkit.backend.messages.responses.MultiDBSupport;
import neo4j.org.testkit.backend.messages.responses.TestkitResponse;

@Setter
@Getter
@NoArgsConstructor
public class CheckMultiDBSupport implements TestkitRequest
{
private CheckMultiDBSupportBody data;

@Override
public TestkitResponse process( TestkitState testkitState )
{
String driverId = data.getDriverId();
boolean available = testkitState.getDrivers().get( driverId ).supportsMultiDb();
return MultiDBSupport.builder().data( MultiDBSupport.MultiDBSupportBody.builder().available( available ).build() ).build();
}

@Setter
@Getter
@NoArgsConstructor
public static class CheckMultiDBSupportBody
{
private String driverId;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
@JsonSubTypes.Type( TransactionRun.class ), @JsonSubTypes.Type( RetryablePositive.class ),
@JsonSubTypes.Type( SessionBeginTransaction.class ), @JsonSubTypes.Type( TransactionCommit.class ),
@JsonSubTypes.Type( SessionLastBookmarks.class ), @JsonSubTypes.Type( SessionWriteTransaction.class ),
@JsonSubTypes.Type( ResolverResolutionCompleted.class )
@JsonSubTypes.Type( ResolverResolutionCompleted.class ), @JsonSubTypes.Type( CheckMultiDBSupport.class )
} )
public interface TestkitRequest
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
* Copyright (c) "Neo4j"
* Neo4j Sweden AB [http://neo4j.com]
*
* This file is part of Neo4j.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package neo4j.org.testkit.backend.messages.responses;

import lombok.Builder;
import lombok.Getter;
import lombok.Setter;

@Setter
@Getter
@Builder
public class MultiDBSupport implements TestkitResponse
{
private final MultiDBSupportBody data;

@Override
public String testkitName()
{
return "MultiDBSupport";
}

@Setter
@Getter
@Builder
public static class MultiDBSupportBody
{
private final String id;

private final boolean available;
}
}

0 comments on commit 1de4b2d

Please sign in to comment.