Skip to content

Refactoring #1477

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions driver/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,6 @@
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
</dependency>
<dependency>
<groupId>org.junit.support</groupId>
<artifactId>testng-engine</artifactId>
</dependency>
<dependency>
<groupId>org.rauschig</groupId>
<artifactId>jarchivelib</artifactId>
Expand Down Expand Up @@ -263,6 +259,18 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<dependencies>
<dependency>
<groupId>org.apache.maven.surefire</groupId>
<artifactId>surefire-junit-platform</artifactId>
<version>${surefire.and.failsafe.version}</version>
</dependency>
<dependency>
<groupId>org.apache.maven.surefire</groupId>
<artifactId>surefire-testng</artifactId>
<version>${surefire.and.failsafe.version}</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>
Expand Down
2 changes: 1 addition & 1 deletion driver/src/main/java/org/neo4j/driver/Values.java
Original file line number Diff line number Diff line change
Expand Up @@ -610,7 +610,7 @@ public static Value parameters(Object... keysAndValues) {
* @return a function that returns the value passed into it - the identity function
*/
public static Function<Value, Value> ofValue() {
return val -> val;
return Function.identity();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import java.util.concurrent.CompletionStage;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicReference;
import java.util.function.Function;
import org.neo4j.driver.AccessMode;
import org.neo4j.driver.AuthToken;
import org.neo4j.driver.Bookmark;
Expand Down Expand Up @@ -112,7 +113,7 @@ public CompletionStage<ResultCursor> runAsync(Query query, TransactionConfig con
resultCursorStage = newResultCursorStage.exceptionally(error -> null);
return newResultCursorStage
.thenCompose(AsyncResultCursor::mapSuccessfulRunCompletionAsync)
.thenApply(cursor -> cursor); // convert the return type
.thenApply(Function.identity()); // convert the return type
}

public CompletionStage<RxResultCursor> runRx(
Expand Down Expand Up @@ -320,7 +321,7 @@ private CompletionStage<Throwable> closeTransactionAndReleaseConnection() {
// there exists an open transaction, let's close it and propagate the error, if any
return tx.closeAsync()
.thenApply(ignore -> (Throwable) null)
.exceptionally(error -> error);
.exceptionally(Function.identity());
}
// no open transaction so nothing to close
return completedWithNull();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ public CompletionStage<ResultCursor> runAsync(Query query) {
resultCursors.add(cursorStage);
return cursorStage
.thenCompose(AsyncResultCursor::mapSuccessfulRunCompletionAsync)
.thenApply(cursor -> cursor);
.thenApply(Function.identity());
}

public CompletionStage<RxResultCursor> runRx(Query query) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ private CompletionStage<RxResultCursor> runAsStage(
}
}
})
.thenCompose(stage -> stage);
.thenCompose(Function.identity());
}

private <T> CompletionStage<T> releaseConnectionAndRethrow(Throwable throwable) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import static org.neo4j.driver.testutil.TestUtil.await;

import java.util.concurrent.ExecutorService;
import java.util.function.Function;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;
Expand Down Expand Up @@ -67,7 +68,7 @@ void shouldErrorToAccessRecordsAfterConsume() {
assertThrows(ResultConsumedException.class, result::peek);
assertThrows(ResultConsumedException.class, () -> result.stream().toArray());
assertThrows(ResultConsumedException.class, () -> result.forEachRemaining(record -> {}));
assertThrows(ResultConsumedException.class, () -> result.list(record -> record));
assertThrows(ResultConsumedException.class, () -> result.list(Function.identity()));
}

@Test
Expand All @@ -88,7 +89,7 @@ void shouldErrorToAccessRecordsAfterClose() {
assertThrows(ResultConsumedException.class, result::peek);
assertThrows(ResultConsumedException.class, () -> result.stream().toArray());
assertThrows(ResultConsumedException.class, () -> result.forEachRemaining(record -> {}));
assertThrows(ResultConsumedException.class, () -> result.list(record -> record));
assertThrows(ResultConsumedException.class, () -> result.list(Function.identity()));
}

@Test
Expand Down Expand Up @@ -145,7 +146,7 @@ void shouldErrorToAccessRecordsAfterConsumeAsync() {
assertThrows(ResultConsumedException.class, () -> await(result.singleAsync()));
assertThrows(ResultConsumedException.class, () -> await(result.forEachAsync(record -> {})));
assertThrows(ResultConsumedException.class, () -> await(result.listAsync()));
assertThrows(ResultConsumedException.class, () -> await(result.listAsync(record -> record)));
assertThrows(ResultConsumedException.class, () -> await(result.listAsync(Function.identity())));
}

@Test
Expand All @@ -164,7 +165,7 @@ void shouldErrorToAccessRecordsAfterCloseAsync() {
assertThrows(ResultConsumedException.class, () -> await(result.singleAsync()));
assertThrows(ResultConsumedException.class, () -> await(result.forEachAsync(record -> {})));
assertThrows(ResultConsumedException.class, () -> await(result.listAsync()));
assertThrows(ResultConsumedException.class, () -> await(result.listAsync(record -> record)));
assertThrows(ResultConsumedException.class, () -> await(result.listAsync(Function.identity())));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ public void onComplete() {
return subscription;
});
}))
.map(future -> future.thenCompose(itself -> itself))
.map(future -> future.thenCompose(Function.identity()))
.toArray(CompletableFuture[]::new);

CompletableFuture.allOf(subscriptionFutures).join();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ protected void hookOnNext(@NonNull ReactiveResult result) {
return subscription;
});
}))
.map(future -> future.thenCompose(itself -> itself))
.map(future -> future.thenCompose(Function.identity()))
.toArray(CompletableFuture[]::new);

CompletableFuture.allOf(subscriptionFutures).join();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import static org.neo4j.driver.testutil.TestUtil.await;

import java.util.concurrent.CompletableFuture;
import java.util.function.Function;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.neo4j.driver.internal.util.Futures;
Expand Down Expand Up @@ -84,7 +85,7 @@ void shouldNotDisposeCursor() {
await(cursor.singleAsync());
await(cursor.forEachAsync(record -> {}));
await(cursor.listAsync());
await(cursor.listAsync(record -> record));
await(cursor.listAsync(Function.identity()));
await(cursor.pullAllFailureAsync());

// Then
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import java.util.function.Function;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
import org.junit.jupiter.api.Test;
Expand Down Expand Up @@ -701,7 +702,7 @@ private void assertMap(int size) throws Throwable {
var packer = machine.packer();
var map = IntStream.range(0, size)
.boxed()
.collect(Collectors.toMap(i -> Integer.toString(i), i -> i, (a, b) -> b, HashMap::new));
.collect(Collectors.toMap(i -> Integer.toString(i), Function.identity(), (a, b) -> b, HashMap::new));
packer.pack(map);

// Then
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -497,8 +497,9 @@ private static Bookmark createNodesAsync(int batchCount, Driver driver) throws T
writeTransactions = writeTransactions.thenCompose(ignore -> session.writeTransactionAsync(
tx -> createNodesInTxAsync(tx, batchIndex, AbstractStressTestBase.BIG_DATA_TEST_BATCH_SIZE)));
}
writeTransactions =
writeTransactions.exceptionally(error -> error).thenCompose(error -> safeCloseSession(session, error));
writeTransactions = writeTransactions
.exceptionally(Function.identity())
.thenCompose(error -> safeCloseSession(session, error));

var error = Futures.blockingGet(writeTransactions);
if (error != null) {
Expand Down Expand Up @@ -532,7 +533,7 @@ private static void readNodesAsync(Driver driver, Bookmark bookmark) throws Thro
verifyNodeProperties(node);
})))
.thenApply(summary -> (Throwable) null)
.exceptionally(error -> error)
.exceptionally(Function.identity())
.thenCompose(error -> safeCloseSession(session, error));

var error = Futures.blockingGet(readQuery);
Expand Down Expand Up @@ -628,7 +629,7 @@ private static CompletionStage<Throwable> createNodesInTxAsync(

return CompletableFuture.allOf(queryFutures)
.thenApply(ignored -> (Throwable) null)
.exceptionally(error -> error);
.exceptionally(Function.identity());
}

private static CompletableFuture<Void> createNodeInTxAsync(AsyncTransaction tx, int nodeIndex) {
Expand Down
16 changes: 5 additions & 11 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@
<hamcrest.version>2.2</hamcrest.version>
<mockito-core.version>5.4.0</mockito-core.version>
<junit.version>5.10.0</junit.version>
<testng-engine.version>1.0.4</testng-engine.version>
<!-- supply a newer version than the one supplied by the reactive-streams 1.0.4 -->
<testng.version>7.8.0</testng.version>
<jarchivelib.version>1.2.0</jarchivelib.version>
<bouncycastle-jdk15on.version>1.70</bouncycastle-jdk15on.version>
<logback-classic.version>1.2.12</logback-classic.version>
Expand Down Expand Up @@ -153,16 +154,9 @@
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.support</groupId>
<artifactId>testng-engine</artifactId>
<version>${testng-engine.version}</version>
<exclusions>
<exclusion>
<!-- Use the version supplied by the org.junit.jupiter:junit-jupiter -->
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-engine</artifactId>
</exclusion>
</exclusions>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>${testng.version}</version>
<scope>test</scope>
</dependency>
<dependency>
Expand Down