@Test
public void testSubspaceReadWriteConflict() throws Exception {

    // create the store, so it won't conflict on that action
    try (FDBRecordContext context = openContext()) {
        openSimpleRecordStore(context);
        context.commit();
    }
    // Double check that it works to have two contexts on same space writing different records without conflict.
    try (FDBRecordContext context1 = openContext()) {
        openSimpleRecordStore(context1);
        FDBRecordStore recordStore1 = recordStore;
        recordStore1.saveRecord(TestRecords1Proto.MySimpleRecord.newBuilder().setRecNo(1).build());
        try (FDBRecordContext context2 = openContext()) {
            openSimpleRecordStore(context2);
            recordStore.saveRecord(TestRecords1Proto.MySimpleRecord.newBuilder().setRecNo(2).build());
            commit(context2);
        }
        commit(context1);
    }
    // Again with requested conflict.
    try (FDBRecordContext context3 = openContext()) {
        openSimpleRecordStore(context3);
        FDBRecordStore recordStore3 = recordStore;
        recordStore3.addConflictForSubspace(false);
        recordStore3.saveRecord(TestRecords1Proto.MySimpleRecord.newBuilder().setRecNo(3).build());
        try (FDBRecordContext context4 = openContext()) {
            uncheckedOpenSimpleRecordStore(context4);
            recordStore.addConflictForSubspace(false);
            recordStore.saveRecord(TestRecords1Proto.MySimpleRecord.newBuilder().setRecNo(4).build());
            commit(context4);
        }
        assertThrows(FDBExceptions.FDBStoreTransactionConflictException.class, () -> commit(context3));
    }
}