Verify installed kit receipt locking and checkpoint rollback (318)
This commit is contained in:
parent
f852d4011a
commit
d1cbc58768
4 changed files with 107 additions and 0 deletions
26
DuneAtelier/RECEIPT-ACCEPTANCE-318.md
Normal file
26
DuneAtelier/RECEIPT-ACCEPTANCE-318.md
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
# Kit delivery: verified receipt boundary (6 November 2026)
|
||||
|
||||
Native ticket 318 / public 968896 remains open. This slice verifies the installed receipt code; it does not deploy the checkpoint's newer enchantment policy or complete Java/Bedrock client acceptance.
|
||||
|
||||
## Reproduce
|
||||
|
||||
With Java 21 and Gradle 8.14.3, run from `DuneAtelier/receipt-qa`:
|
||||
|
||||
```sh
|
||||
gradle test --no-daemon
|
||||
gradle test --no-daemon --rerun-tasks -PinstalledArtifact=/absolute/path/to/installed-DuneAtelier.jar
|
||||
```
|
||||
|
||||
The first command compiles only the receipt store from source. The second compiles **no production source** and tests the store loaded from the selected installed JAR. Neither opens the game database or creates a real purchase, code, entitlement, player or inventory item.
|
||||
|
||||
Ten tests cover wrong-owner denial, fenced transactions, explicit redemption queues, repeat consumption, malformed cosmetics, concurrent receipt locking, receipt/checkpoint rollback and preservation of the original paid snapshot. The concurrent test uses two independent JDBC connections: the second claimant waits while the first owns the row, then rejects the consumed receipt after the first commits. A separate rollback case restores both a synthetic four-piece inventory checkpoint and its receipt before a successful retry.
|
||||
|
||||
The database fixture is H2 in MySQL compatibility mode. It proves this JDBC/receipt contract, **not** production MySQL isolation, Bukkit inventory behavior, cross-server transfer or recovery after a process crash. The existing Core owns the real inventory checkpoint and quarantines an uncertain commit; no stronger distributed exactly-once guarantee is asserted here.
|
||||
|
||||
## Live/source difference and remaining work
|
||||
|
||||
The active Arrakis plugin is `DuneAtelier-1.0.0.jar`. Its factory preserves the faction kit's combat properties and decorates cosmetics. The current checkpoint source has a separate `KitEnchantments` quality policy absent from that installed JAR. Do not replace the whole live plugin to obtain a receipt-only change: that would also ship untested menus and combat changes.
|
||||
|
||||
Keep historical paid snapshots and earned progression intact. The superseded paid-power Legendary+ proposal is not permission to introduce paid combat bonuses. No token consumption or existing purchase migration has been performed.
|
||||
|
||||
Full acceptance still needs controlled actual Java and Bedrock sessions, full/partially full inventory behavior, reconnect/server transfer, permission revocation and failure/crash recovery, plus an explicit policy-compatible decision on the older consolidated upgrade requirements. Minecraft Bedrock was present on the available Windows PC, but launching it exposed no targetable window; no client acceptance is claimed.
|
||||
19
DuneAtelier/receipt-qa/build.gradle.kts
Normal file
19
DuneAtelier/receipt-qa/build.gradle.kts
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
plugins { java }
|
||||
repositories { mavenCentral() }
|
||||
val installedArtifact = providers.gradleProperty("installedArtifact").orNull
|
||||
dependencies {
|
||||
implementation("com.google.code.gson:gson:2.11.0")
|
||||
if (installedArtifact != null) testImplementation(files(installedArtifact))
|
||||
testImplementation("com.h2database:h2:2.3.232")
|
||||
testImplementation("org.junit.jupiter:junit-jupiter:5.11.4")
|
||||
testRuntimeOnly("org.junit.platform:junit-platform-launcher")
|
||||
}
|
||||
java { toolchain.languageVersion.set(JavaLanguageVersion.of(21)) }
|
||||
sourceSets {
|
||||
main {
|
||||
if (installedArtifact == null) { java.setSrcDirs(listOf("../src/main/java")); java.include("**/DeliveryStore.java") }
|
||||
else java.setSrcDirs(emptyList<String>())
|
||||
}
|
||||
test { java.setSrcDirs(listOf("../src/test/java")); java.include("**/DeliveryStoreTest.java", "**/DeliveryCheckpointTest.java") }
|
||||
}
|
||||
tasks.test { useJUnitPlatform(); testLogging { events("passed", "failed", "skipped") } }
|
||||
1
DuneAtelier/receipt-qa/settings.gradle.kts
Normal file
1
DuneAtelier/receipt-qa/settings.gradle.kts
Normal file
|
|
@ -0,0 +1 @@
|
|||
rootProject.name = "atelier-receipt-qa"
|
||||
|
|
@ -0,0 +1,61 @@
|
|||
package com.dunerealms.atelier;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import java.sql.*;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.*;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
/** Receipt/checkpoint contract, also runnable against the installed plugin JAR. */
|
||||
class DeliveryCheckpointTest {
|
||||
private final UUID owner=UUID.randomUUID(), order=UUID.randomUUID();
|
||||
private final String url="jdbc:h2:mem:"+UUID.randomUUID()+";MODE=MySQL;DATABASE_TO_LOWER=TRUE;DB_CLOSE_DELAY=-1;LOCK_TIMEOUT=5000";
|
||||
private final String snapshot="{\"blueprintId\":\""+UUID.randomUUID()+"\",\"name\":\"Original paid name\",\"color\":\"#123456\",\"quality\":\"rare\",\"lore\":[\"Original paid lore\"]}";
|
||||
private Connection database() throws Exception {
|
||||
Connection c=DriverManager.getConnection(url);
|
||||
try(Statement s=c.createStatement()) {
|
||||
s.execute("CREATE TABLE dune_kit_sales(id VARCHAR(36) PRIMARY KEY,buyer_uuid VARCHAR(36),snapshot_json TEXT,completed_at BIGINT,redeem_requested_at BIGINT,delivered_at BIGINT)");
|
||||
s.execute("CREATE TABLE inventory_checkpoint(player_uuid VARCHAR(36) PRIMARY KEY,pieces INT)");
|
||||
}
|
||||
try(PreparedStatement q=c.prepareStatement("INSERT INTO dune_kit_sales VALUES(?,?,?,1,NULL,NULL)")) {
|
||||
q.setString(1,order.toString());q.setString(2,owner.toString());q.setString(3,snapshot);q.executeUpdate();
|
||||
}
|
||||
try(PreparedStatement q=c.prepareStatement("INSERT INTO inventory_checkpoint VALUES(?,0)")) {q.setString(1,owner.toString());q.executeUpdate();}
|
||||
c.setAutoCommit(false);return c;
|
||||
}
|
||||
private int pieces(Connection c) throws Exception {try(Statement q=c.createStatement();ResultSet r=q.executeQuery("SELECT pieces FROM inventory_checkpoint")){assertTrue(r.next());return r.getInt(1);}}
|
||||
private void addCheckpoint(Connection c) throws Exception {try(Statement q=c.createStatement()){assertEquals(1,q.executeUpdate("UPDATE inventory_checkpoint SET pieces=pieces+4"));}}
|
||||
@Test void twoConnectionsCannotConsumeTheSameReceipt() throws Exception {
|
||||
try(Connection first=database()) {
|
||||
first.commit();DeliveryStore store=new DeliveryStore();assertNotNull(store.lock(first,owner,order));
|
||||
CountDownLatch attempting=new CountDownLatch(1);ExecutorService worker=Executors.newSingleThreadExecutor();
|
||||
try {
|
||||
Future<Boolean> second=worker.submit(()->{try(Connection c=DriverManager.getConnection(url)){c.setAutoCommit(false);attempting.countDown();try{store.lock(c,owner,order);return false;}catch(SQLException expected){return true;}finally{c.rollback();}}});
|
||||
assertTrue(attempting.await(2,TimeUnit.SECONDS));assertThrows(TimeoutException.class,()->second.get(150,TimeUnit.MILLISECONDS));
|
||||
addCheckpoint(first);store.delivered(first,owner,order,2);first.commit();
|
||||
assertTrue(second.get(3,TimeUnit.SECONDS));assertEquals(4,pieces(first));assertTrue(store.pending(first,owner,false).isEmpty());
|
||||
} finally {first.rollback();worker.shutdownNow();assertTrue(worker.awaitTermination(6,TimeUnit.SECONDS));}
|
||||
}
|
||||
}
|
||||
@Test void checkpointAndReceiptRollbackTogetherAfterInsertionFailure() throws Exception {
|
||||
try(Connection c=database()) {
|
||||
c.commit();DeliveryStore store=new DeliveryStore();store.lock(c,owner,order);addCheckpoint(c);store.delivered(c,owner,order,2);
|
||||
c.rollback();assertEquals(0,pieces(c));assertNotNull(store.lock(c,owner,order));
|
||||
addCheckpoint(c);store.delivered(c,owner,order,3);c.commit();assertEquals(4,pieces(c));assertThrows(SQLException.class,()->store.lock(c,owner,order));
|
||||
}
|
||||
}
|
||||
@Test void snapshotNameLoreAndQualityRemainThePaidValuesAfterConsumption() throws Exception {
|
||||
try(Connection c=database()) {
|
||||
DeliveryStore store=new DeliveryStore();var design=store.lock(c,owner,order);
|
||||
assertEquals("Original paid name",design.name());assertEquals("Original paid lore",design.lore().getFirst());assertEquals("rare",design.quality());
|
||||
addCheckpoint(c);store.delivered(c,owner,order,2);c.commit();
|
||||
try(PreparedStatement q=c.prepareStatement("SELECT snapshot_json FROM dune_kit_sales WHERE id=?")){q.setString(1,order.toString());try(ResultSet r=q.executeQuery()){assertTrue(r.next());assertEquals(snapshot,r.getString(1));}}
|
||||
}
|
||||
}
|
||||
@Test void anotherOwnerCannotConsumeOrChangeTheCheckpoint() throws Exception {
|
||||
try(Connection c=database()) {
|
||||
DeliveryStore store=new DeliveryStore();UUID other=UUID.randomUUID();assertThrows(SQLException.class,()->store.lock(c,other,order));assertThrows(SQLException.class,()->store.delivered(c,other,order,2));
|
||||
assertEquals(0,pieces(c));assertNotNull(store.lock(c,owner,order));assertEquals(1,store.pending(c,owner,false).size());
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue

Staff