Skip to content

Commit

Permalink
Merge pull request #22 from prdoyle/newer-java
Browse files Browse the repository at this point in the history
Upgrade to JDK 22
  • Loading branch information
prdoyle authored Aug 18, 2024
2 parents 8fae481 + 4b2586d commit fa45049
Show file tree
Hide file tree
Showing 32 changed files with 195 additions and 129 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/build-and-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,10 @@ jobs:

- uses: actions/setup-java@v4
with:
java-version: '17'
distribution: temurin
java-version: |
22
17
- uses: gradle/actions/setup-gradle@v3
with:
Expand Down
8 changes: 3 additions & 5 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,10 @@ jobs:

- uses: actions/setup-java@v4
with:
java-version: '17'
distribution: temurin
server-id: ossrh
server-username: ${{ secrets.OSSRH_USERNAME }}
server-password: ${{ secrets.OSSRH_TOKEN }}
gpg-private-key: ${{ secrets.GPG_PRIVATE_KEY }}
java-version: |
22
17
- uses: gradle/actions/setup-gradle@v3

Expand Down
13 changes: 11 additions & 2 deletions bosk-annotations/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,17 @@ plugins {
}

java {
sourceCompatibility = '17'
targetCompatibility = '17'
toolchain {
languageVersion = JavaLanguageVersion.of(22)
}
}

compileJava {
options.release = 17
}

compileTestJava {
options.release = null
}

repositories {
Expand Down
13 changes: 11 additions & 2 deletions bosk-core/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,17 @@ plugins {
}

java {
sourceCompatibility = '17'
targetCompatibility = '17'
toolchain {
languageVersion = JavaLanguageVersion.of(22)
}
}

compileJava {
options.release = 17
}

compileTestJava {
options.release = null
}

dependencies {
Expand Down
21 changes: 10 additions & 11 deletions bosk-core/src/test/java/works/bosk/BoskConstructorTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import java.io.IOException;
import java.lang.reflect.Type;
import java.util.concurrent.atomic.AtomicReference;
import lombok.val;
import org.jetbrains.annotations.NotNull;
import org.junit.jupiter.api.Test;
import works.bosk.Bosk.DefaultRootFunction;
Expand Down Expand Up @@ -37,7 +36,7 @@ void basicProperties_correctValues() {
Bosk<StateTreeNode> bosk = new Bosk<StateTreeNode>(
name,
rootType,
__ -> root,
_ -> root,
(b,d)-> {
driver.set(new ForwardingDriver<>(singleton(d)));
return driver.get();
Expand All @@ -50,7 +49,7 @@ void basicProperties_correctValues() {

assertSame(driver.get(), bosk.getDriver(ForwardingDriver.class));

try (val __ = bosk.readContext()) {
try (var _ = bosk.readContext()) {
assertSame(root, bosk.rootReference().value());
}
}
Expand Down Expand Up @@ -81,9 +80,9 @@ void badDriverInitialRoot_throws() {

@Test
void badDefaultRootFunction_throws() {
assertDefaultRootThrows(NullPointerException.class, __ -> null);
assertDefaultRootThrows(ClassCastException.class, __ -> new TypeValidationTest.CatalogOfInvalidType(Identifier.from("whoops"), Catalog.empty()));
assertDefaultRootThrows(IllegalArgumentException.class, __ -> { throw new InvalidTypeException("Whoopsie"); });
assertDefaultRootThrows(NullPointerException.class, _ -> null);
assertDefaultRootThrows(ClassCastException.class, _ -> new TypeValidationTest.CatalogOfInvalidType(Identifier.from("whoops"), Catalog.empty()));
assertDefaultRootThrows(IllegalArgumentException.class, _ -> { throw new InvalidTypeException("Whoopsie"); });
}

@Test
Expand All @@ -104,9 +103,9 @@ void driverInitialRoot_matches() {
Bosk<StateTreeNode> bosk = new Bosk<StateTreeNode>(
boskName(),
SimpleTypes.class,
__ -> {throw new AssertionError("Shouldn't be called");},
_ -> {throw new AssertionError("Shouldn't be called");},
initialRootDriver(()->root));
try (val __ = bosk.readContext()) {
try (var _ = bosk.readContext()) {
assertSame(root, bosk.rootReference().value());
}
}
Expand All @@ -116,14 +115,14 @@ void defaultRoot_matches() {
SimpleTypes root = newEntity();
{
Bosk<StateTreeNode> valueBosk = new Bosk<>(boskName(), SimpleTypes.class, root, Bosk::simpleDriver);
try (val __ = valueBosk.readContext()) {
try (var _ = valueBosk.readContext()) {
assertSame(root, valueBosk.rootReference().value());
}
}

{
Bosk<StateTreeNode> functionBosk = new Bosk<StateTreeNode>(boskName(), SimpleTypes.class, __ -> root, Bosk::simpleDriver);
try (val __ = functionBosk.readContext()) {
Bosk<StateTreeNode> functionBosk = new Bosk<StateTreeNode>(boskName(), SimpleTypes.class, _ -> root, Bosk::simpleDriver);
try (var _ = functionBosk.readContext()) {
assertSame(root, functionBosk.rootReference().value());
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ void setupBosk() throws InvalidTypeException {
void hookRegistration_propagatesDiagnosticContext() throws IOException, InterruptedException {
Semaphore diagnosticsVerified = new Semaphore(0);
bosk.driver().flush();
try (var __ = bosk.diagnosticContext().withAttribute("attributeName", "attributeValue")) {
try (var _ = bosk.diagnosticContext().withAttribute("attributeName", "attributeValue")) {
bosk.registerHook("contextPropagatesToHook", bosk.rootReference(), ref -> {
assertEquals("attributeValue", bosk.diagnosticContext().getAttribute("attributeName"));
assertEquals(MapValue.singleton("attributeName", "attributeValue"), bosk.diagnosticContext().getAttributes());
Expand Down
31 changes: 15 additions & 16 deletions bosk-core/src/test/java/works/bosk/BoskLocalReferenceTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
import lombok.experimental.Delegate;
import lombok.experimental.FieldDefaults;
import lombok.experimental.FieldNameConstants;
import lombok.val;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import works.bosk.annotations.ReferencePath;
Expand Down Expand Up @@ -163,7 +162,7 @@ void testListingReference() throws Exception {
// Check references to the Listing contents
Listing<TestEntity> listing;
Map<Identifier, TestEntity> entries;
try (val __ = bosk.readContext()) {
try (var _ = bosk.readContext()) {
listing = listingRef.value();
entries = listing.valueMap();
}
Expand Down Expand Up @@ -206,7 +205,7 @@ void testSideTableReference() throws InvalidTypeException {
} catch (AssertionError e) {
throw new AssertionError("Failed checkRefence on id " + id + ", sideTableRef " + sideTableRef);
}
try (val __ = bosk.readContext()) {
try (var _ = bosk.readContext()) {
for (Entry<Identifier, String> entry: sideTable.idEntrySet()) {
Identifier key = entry.getKey();
Reference<String> entryRef = sideTableRef.then(key);
Expand Down Expand Up @@ -290,7 +289,7 @@ private <T> void checkReferenceProperties(Reference<T> ref, Path expectedPath, T
assertEquals(expectedPath.urlEncoded(), ref.pathString());

assertThrows(IllegalStateException.class, ref::value, "Can't read before ReadContext");
try (val __ = bosk.readContext()) {
try (var _ = bosk.readContext()) {
T actualValue = ref.valueIfExists();
assertSame(expectedValue, actualValue);

Expand Down Expand Up @@ -322,7 +321,7 @@ private void checkEntityReference(Reference<TestEntity> ref, Path expectedPath,
assertEquals(expectedPath.then(TestEntity.Fields.listing), ref.then(Listing.class, TestEntity.Fields.listing).path());
assertEquals(expectedPath.then(TestEntity.Fields.sideTable), ref.then(SideTable.class, TestEntity.Fields.sideTable).path());

try (val __ = bosk.readContext()) {
try (var _ = bosk.readContext()) {
if (expectedValue == null) {
assertNull(ref.then(Catalog.class, TestEntity.Fields.catalog).valueIfExists());
assertNull(ref.then(Listing.class, TestEntity.Fields.listing).valueIfExists());
Expand All @@ -339,33 +338,33 @@ private <T> void checkUpdates(Reference<T> ref, UnaryOperator<T> updater) throws
Root originalRoot;
T firstValue;
assertThrows(IllegalStateException.class, ref::value, "Can't read from Bosk before ReadContext");
try (val __ = bosk.readContext()) {
try (var _ = bosk.readContext()) {
originalRoot = bosk.rootReference().value();
firstValue = ref.value();
}
assertThrows(IllegalStateException.class, ref::value, "Can't read from Bosk between ReadContexts");

T secondValue = updater.apply(firstValue);
T thirdValue = updater.apply(secondValue);
try (val __ = bosk.readContext()) {
try (var _ = bosk.readContext()) {
assertSame(firstValue, ref.value(), "New ReadContext sees same value as before");
bosk.driver().submitReplacement(ref, secondValue);
assertSame(firstValue, ref.value(), "Bosk updates not visible during the same ReadContext");

try (val ___ = bosk.supersedingReadContext()) {
try (var _ = bosk.supersedingReadContext()) {
assertSame(secondValue, ref.value(), "Superseding context sees the latest state");
try (val ____ = bosk.readContext()) {
try (var _ = bosk.readContext()) {
assertSame(secondValue, ref.value(), "Nested context matches outer context");
}
}

try (val ___ = bosk.readContext()) {
try (var _ = bosk.readContext()) {
assertSame(firstValue, ref.value(), "Nested context matches original outer context");
}
}

try (
val context = bosk.readContext();
var context = bosk.readContext();
) {
assertSame(secondValue, ref.value(), "New value is visible in next ReadContext");
bosk.driver().submitReplacement(ref, thirdValue);
Expand All @@ -382,13 +381,13 @@ private <T> void checkUpdates(Reference<T> ref, UnaryOperator<T> updater) throws
fail("Unexpected exception: ", e);
}
assertNotNull(caught, "New thread should not have any scope by default, so an exception should be thrown");
try (val unrelatedContext = bosk.readContext()) {
try (var _ = bosk.readContext()) {
assertSame(thirdValue, ref.value(), "Separate thread should see the latest state");
}
try (val inheritedContext = context.adopt()) {
try (var inheritedContext = context.adopt()) {
assertSame(secondValue, ref.value(), "Inherited scope should see the same state");

try (val reinheritedContext = inheritedContext.adopt()) {
try (var _ = inheritedContext.adopt()) {
// Harmless to re-assert a scope you're already in
assertSame(secondValue, ref.value(), "Inner scope should see the same state");
}
Expand All @@ -408,13 +407,13 @@ private <T> void checkUpdates(Reference<T> ref, UnaryOperator<T> updater) throws

private <T> void checkDeletion(Reference<T> ref, T expectedValue) {
Root originalRoot;
try (val __ = bosk.readContext()) {
try (var _ = bosk.readContext()) {
originalRoot = bosk.rootReference().value();
assertSame(expectedValue, ref.valueIfExists(), "Value is present before deletion");
bosk.driver().submitDeletion(ref);
assertSame(expectedValue, ref.valueIfExists(), "Bosk deletions not visible during the same ReadContext");
}
try (val __ = bosk.readContext()) {
try (var _ = bosk.readContext()) {
assertThrows(NonexistentReferenceException.class, ref::value);
if (expectedValue != null) {
bosk.driver().submitReplacement(ref, expectedValue);
Expand Down
5 changes: 2 additions & 3 deletions bosk-core/src/test/java/works/bosk/BoskUpdateTest.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package works.bosk;

import java.io.IOException;
import lombok.val;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import works.bosk.annotations.ReferencePath;
Expand Down Expand Up @@ -47,7 +46,7 @@ void createBosk() throws InvalidTypeException {
Bosk::simpleDriver
);
refs = bosk.buildReferences(Refs.class);
try (val __ = bosk.readContext()) {
try (var _ = bosk.readContext()) {
originalRoot = bosk.rootReference().value();
originalParent = refs.entity(PARENT_ID).value();
originalChild1 = refs.child(PARENT_ID, CHILD_1_ID).value();
Expand Down Expand Up @@ -153,7 +152,7 @@ void conditionalReplaceIDMismatchesNonNull_nothingChanged() throws IOException,

<T> void assertValueEquals(T expected, Reference<T> ref) throws IOException, InterruptedException {
bosk.driver().flush();
try (val __ = bosk.readContext()) {
try (var _ = bosk.readContext()) {
assertEquals(expected, ref.valueIfExists());
}
}
Expand Down
9 changes: 4 additions & 5 deletions bosk-core/src/test/java/works/bosk/HooksTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.atomic.AtomicBoolean;
import lombok.val;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
Expand Down Expand Up @@ -49,7 +48,7 @@ public interface Refs {
void setupBosk() throws InvalidTypeException {
bosk = setUpBosk(Bosk::simpleDriver);
refs = bosk.rootReference().buildReferences(Refs.class);
try (val __ = bosk.readContext()) {
try (var _ = bosk.readContext()) {
originalRoot = bosk.rootReference().value();
originalParent = refs.parent().value();
originalChild1 = refs.child(child1).value();
Expand Down Expand Up @@ -449,7 +448,7 @@ void nestedMultipleUpdates_breadthFirst() {
recorder.events(),
"All hooks for an update should be called before any hooks for subsequent updates");

try (val __ = bosk.readContext()) {
try (var _ = bosk.readContext()) {
assertEquals(expectedParent, refs.parent().value());
}
}
Expand All @@ -461,7 +460,7 @@ void nested_correctReadContext() {
recorder.restart();
String expectedString = "expected string";

try (val __ = bosk.readContext()) {
try (var _ = bosk.readContext()) {
bosk.driver().submitReplacement(refs.childString(child2), expectedString);
// If the hook were to run accidentally in this ReadContext, it would
// see originalChild2.string() instead of expectedString.
Expand All @@ -473,7 +472,7 @@ void nested_correctReadContext() {
"Hooks run in the right ReadContext regardless of active read scope at submission or execution time");


try (val __ = bosk.readContext()) {
try (var _ = bosk.readContext()) {
assertEquals(expectedString, refs.childString(child2).value(), "Correct value got copied");
}
}
Expand Down
13 changes: 6 additions & 7 deletions bosk-core/src/test/java/works/bosk/ListingTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
import lombok.RequiredArgsConstructor;
import lombok.experimental.FieldDefaults;
import lombok.experimental.FieldNameConstants;
import lombok.val;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtensionContext;
Expand Down Expand Up @@ -107,7 +106,7 @@ public static class TestEntity implements Entity {
@ParameterizedTest
@ArgumentsSource(ListingArgumentProvider.class)
void testGet(Listing<TestEntity> listing, List<TestEntity> children, Bosk<TestEntity> bosk) throws InvalidTypeException {
try (val context = bosk.readContext()) {
try (var _ = bosk.readContext()) {
for (TestEntity child: children) {
TestEntity actual = listing.getValue(child.id());
assertSame(child, actual, "All expected entities should be present in the Listing");
Expand All @@ -129,7 +128,7 @@ void testGet(Listing<TestEntity> listing, List<TestEntity> children, Bosk<TestEn
void testValueIterator(Listing<TestEntity> listing, List<TestEntity> children, Bosk<TestEntity> bosk) {
Iterator<TestEntity> expected = children.iterator();
Iterator<TestEntity> actual;
try (val context = bosk.readContext()) {
try (var _ = bosk.readContext()) {
// ReadContext is needed only when creating the iterator
actual = listing.valueIterator();
}
Expand Down Expand Up @@ -169,7 +168,7 @@ void testIdStream(Listing<TestEntity> listing, List<TestEntity> children, Bosk<T
void testStream(Listing<TestEntity> listing, List<TestEntity> children, Bosk<TestEntity> bosk) {
Iterator<TestEntity> expected = children.iterator();
Stream<TestEntity> stream;
try (val context = bosk.readContext()) {
try (var _ = bosk.readContext()) {
// ReadContext is needed only when creating the stream
stream = listing.valueStream();
}
Expand All @@ -180,7 +179,7 @@ void testStream(Listing<TestEntity> listing, List<TestEntity> children, Bosk<Tes
@ArgumentsSource(ListingArgumentProvider.class)
void testAsCollection(Listing<TestEntity> listing, List<TestEntity> children, Bosk<TestEntity> bosk) {
Collection<TestEntity> actual;
try (val context = bosk.readContext()) {
try (var _ = bosk.readContext()) {
// ReadContext is needed only when creating the collection
actual = listing.valueList();
}
Expand Down Expand Up @@ -208,7 +207,7 @@ void testSpliterator(Listing<TestEntity> listing, List<TestEntity> children, Bos
}

Spliterator<TestEntity> newSplit;
try (val context = bosk.readContext()) {
try (var _ = bosk.readContext()) {
newSplit = listing.values().spliterator();
}

Expand Down Expand Up @@ -257,7 +256,7 @@ void testEmpty() throws InvalidTypeException {
assertEquals(0, actual.size());

Iterator<TestEntity> iterator;
try (val context = bosk.readContext()) {
try (var _ = bosk.readContext()) {
// iterator() needs a ReadContext at creation time
iterator = actual.valueIterator();
}
Expand Down
Loading

0 comments on commit fa45049

Please sign in to comment.