Search in sources :

Example 6 with Hash

use of org.projectnessie.versioned.Hash in project nessie by projectnessie.

the class AbstractDatabaseAdapterTest method recreateDefaultBranch.

@Test
void recreateDefaultBranch() throws Exception {
    BranchName main = BranchName.of("main");
    Hash mainHead = databaseAdapter.hashOnReference(main, Optional.empty());
    databaseAdapter.delete(main, Optional.of(mainHead));
    assertThatThrownBy(() -> databaseAdapter.hashOnReference(main, Optional.empty())).isInstanceOf(ReferenceNotFoundException.class);
    databaseAdapter.create(main, null);
    databaseAdapter.hashOnReference(main, Optional.empty());
}
Also used : BranchName(org.projectnessie.versioned.BranchName) Hash(org.projectnessie.versioned.Hash) Test(org.junit.jupiter.api.Test)

Example 7 with Hash

use of org.projectnessie.versioned.Hash in project nessie by projectnessie.

the class AbstractDuplicateTable method duplicateTableOnBranches.

/**
 * Test behavior when a table (content-key) is created on two different branches using either
 * table-types with and without global-states and same/different content-ids.
 */
@ParameterizedTest
@EnumSource(value = DuplicateTableMode.class)
void duplicateTableOnBranches(DuplicateTableMode mode) throws Throwable {
    Key key = Key.of("some", "table");
    BranchName branch0 = BranchName.of("globalStateDuplicateTable-main");
    store().create(branch0, Optional.empty());
    // commit just something to have a "real" common ancestor and not "beginning of time", which
    // means no-common-ancestor
    Hash ancestor = store().commit(branch0, Optional.empty(), commitMessage("initial commit"), ImmutableList.of(Put.of(Key.of("unrelated", "table"), newOnRef("value"))));
    // Create a table with the same name on two branches.
    // WITH global-states, that must fail
    // WITHOUT global-state, it is okay to work
    BranchName branch1 = BranchName.of("globalStateDuplicateTable-branch1");
    BranchName branch2 = BranchName.of("globalStateDuplicateTable-branch2");
    assertThat(store().create(branch1, Optional.of(ancestor))).isEqualTo(ancestor);
    assertThat(store().create(branch2, Optional.of(ancestor))).isEqualTo(ancestor);
    List<Operation<BaseContent>> putForBranch1;
    List<Operation<BaseContent>> putForBranch2;
    BaseContent valuebranch1;
    BaseContent valuebranch2;
    switch(mode) {
        case NO_GLOBAL:
            valuebranch1 = newOnRef("create table");
            valuebranch2 = newOnRef("create table");
            putForBranch1 = ImmutableList.of(Put.of(key, valuebranch1));
            putForBranch2 = ImmutableList.of(Put.of(key, valuebranch2));
            break;
        case STATEFUL_SAME_CONTENT_ID:
            valuebranch1 = withGlobal("state", "create table", "content-id-equal");
            valuebranch2 = withGlobal("state", "create table", "content-id-equal");
            putForBranch1 = singletonList(Put.of(key, withGlobal("state", "create table", "content-id-equal")));
            putForBranch2 = singletonList(Put.of(key, withGlobal("state", "create table", "content-id-equal")));
            break;
        case STATEFUL_DIFFERENT_CONTENT_ID:
            valuebranch1 = withGlobal("state", "create table", "content-id-1");
            valuebranch2 = withGlobal("state", "create table", "content-id-2");
            putForBranch1 = singletonList(Put.of(key, withGlobal("state", "create table", "content-id-1")));
            putForBranch2 = singletonList(Put.of(key, withGlobal("state", "create table", "content-id-2")));
            break;
        default:
            throw new IllegalStateException();
    }
    store().commit(branch1, Optional.empty(), commitMessage("create table"), putForBranch1);
    assertThat(store().getValue(branch1, key)).isEqualTo(valuebranch1);
    ThrowingCallable createTableOnOtherBranch = () -> store().commit(branch2, Optional.empty(), commitMessage("create table on other branch"), putForBranch2);
    if (mode == DuplicateTableMode.STATEFUL_SAME_CONTENT_ID) {
        assertThatThrownBy(createTableOnOtherBranch).isInstanceOf(ReferenceConflictException.class).hasMessage("Global-state for content-id 'content-id-equal' already exists.");
        assertThat(store().getValue(branch2, key)).isNull();
    } else {
        createTableOnOtherBranch.call();
        assertThat(store().getValue(branch2, key)).isEqualTo(valuebranch2);
    }
}
Also used : BaseContent(org.projectnessie.versioned.testworker.BaseContent) ThrowingCallable(org.assertj.core.api.ThrowableAssert.ThrowingCallable) ReferenceConflictException(org.projectnessie.versioned.ReferenceConflictException) BranchName(org.projectnessie.versioned.BranchName) Operation(org.projectnessie.versioned.Operation) Hash(org.projectnessie.versioned.Hash) Key(org.projectnessie.versioned.Key) EnumSource(org.junit.jupiter.params.provider.EnumSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 8 with Hash

use of org.projectnessie.versioned.Hash in project nessie by projectnessie.

the class AbstractGetNamedReferences method parameterValidationNamedRef.

@Test
public void parameterValidationNamedRef() throws Exception {
    BranchName main = BranchName.of(MAIN_BRANCH);
    BranchName parameterValidation = BranchName.of("parameterValidation");
    TagName parameterValidationTag = TagName.of("parameterValidationTag");
    Hash hash = databaseAdapter.noAncestorHash();
    assertThat(databaseAdapter.hashOnReference(main, Optional.empty())).isEqualTo(hash);
    databaseAdapter.create(parameterValidation, hash);
    databaseAdapter.create(parameterValidationTag, hash);
    assertAll(() -> assertThatThrownBy(() -> databaseAdapter.namedRef(main.getName(), null)).isInstanceOf(NullPointerException.class).hasMessage("Parameter for GetNamedRefsParams must not be null"), () -> assertThatThrownBy(() -> databaseAdapter.namedRef(parameterValidation.getName(), GetNamedRefsParams.builder().branchRetrieveOptions(COMPUTE_AHEAD_BEHIND).build())).isInstanceOf(NullPointerException.class).hasMessage("Base reference name missing."), () -> assertThatThrownBy(() -> databaseAdapter.namedRef(parameterValidation.getName(), GetNamedRefsParams.builder().tagRetrieveOptions(COMPUTE_AHEAD_BEHIND).build())).isInstanceOf(NullPointerException.class).hasMessage("Base reference name missing."), () -> assertThatThrownBy(() -> databaseAdapter.namedRef(parameterValidation.getName(), GetNamedRefsParams.builder().branchRetrieveOptions(COMPUTE_COMMON_ANCESTOR).build())).isInstanceOf(NullPointerException.class).hasMessage("Base reference name missing."), () -> assertThatThrownBy(() -> databaseAdapter.namedRef(parameterValidation.getName(), GetNamedRefsParams.builder().tagRetrieveOptions(COMPUTE_COMMON_ANCESTOR).build())).isInstanceOf(NullPointerException.class).hasMessage("Base reference name missing."), () -> assertThatThrownBy(() -> databaseAdapter.namedRef(parameterValidation.getName(), GetNamedRefsParams.builder().branchRetrieveOptions(COMPUTE_AHEAD_BEHIND).tagRetrieveOptions(COMPUTE_AHEAD_BEHIND).baseReference(BranchName.of("no-no-no")).build())).isInstanceOf(ReferenceNotFoundException.class).hasMessage("Named reference 'no-no-no' not found"), () -> assertThatThrownBy(() -> databaseAdapter.namedRef(parameterValidation.getName(), GetNamedRefsParams.builder().branchRetrieveOptions(COMPUTE_AHEAD_BEHIND).tagRetrieveOptions(COMPUTE_AHEAD_BEHIND).baseReference(TagName.of("blah-no")).build())).isInstanceOf(ReferenceNotFoundException.class).hasMessage("Named reference 'blah-no' not found"), () -> assertThatThrownBy(() -> databaseAdapter.namedRef(parameterValidationTag.getName(), GetNamedRefsParams.builder().tagRetrieveOptions(RetrieveOptions.OMIT).build())).isInstanceOf(ReferenceNotFoundException.class).hasMessage("Named reference '" + parameterValidationTag.getName() + "' not found"));
}
Also used : TagName(org.projectnessie.versioned.TagName) BranchName(org.projectnessie.versioned.BranchName) Hash(org.projectnessie.versioned.Hash) Test(org.junit.jupiter.api.Test)

Example 9 with Hash

use of org.projectnessie.versioned.Hash in project nessie by projectnessie.

the class AbstractGetNamedReferences method parameterValidationNamedRefs.

@Test
public void parameterValidationNamedRefs() throws Exception {
    BranchName main = BranchName.of(MAIN_BRANCH);
    BranchName parameterValidation = BranchName.of("parameterValidation");
    TagName parameterValidationTag = TagName.of("parameterValidationTag");
    Hash hash = databaseAdapter.noAncestorHash();
    assertThat(databaseAdapter.hashOnReference(main, Optional.empty())).isEqualTo(hash);
    databaseAdapter.create(parameterValidation, hash);
    databaseAdapter.create(parameterValidationTag, hash);
    assertAll(() -> assertThatThrownBy(() -> databaseAdapter.namedRefs(null)).isInstanceOf(NullPointerException.class).hasMessage("Parameter for GetNamedRefsParams must not be null."), () -> assertThatThrownBy(() -> databaseAdapter.namedRefs(GetNamedRefsParams.builder().branchRetrieveOptions(COMPUTE_AHEAD_BEHIND).build())).isInstanceOf(NullPointerException.class).hasMessage("Base reference name missing."), () -> assertThatThrownBy(() -> databaseAdapter.namedRefs(GetNamedRefsParams.builder().tagRetrieveOptions(COMPUTE_AHEAD_BEHIND).build())).isInstanceOf(NullPointerException.class).hasMessage("Base reference name missing."), () -> assertThatThrownBy(() -> databaseAdapter.namedRefs(GetNamedRefsParams.builder().branchRetrieveOptions(COMPUTE_COMMON_ANCESTOR).build())).isInstanceOf(NullPointerException.class).hasMessage("Base reference name missing."), () -> assertThatThrownBy(() -> databaseAdapter.namedRefs(GetNamedRefsParams.builder().tagRetrieveOptions(COMPUTE_COMMON_ANCESTOR).build())).isInstanceOf(NullPointerException.class).hasMessage("Base reference name missing."), () -> assertThatThrownBy(() -> databaseAdapter.namedRefs(GetNamedRefsParams.builder().branchRetrieveOptions(COMPUTE_AHEAD_BEHIND).tagRetrieveOptions(COMPUTE_AHEAD_BEHIND).baseReference(BranchName.of("no-no-no")).build())).isInstanceOf(ReferenceNotFoundException.class).hasMessage("Named reference 'no-no-no' not found"), () -> assertThatThrownBy(() -> databaseAdapter.namedRefs(GetNamedRefsParams.builder().branchRetrieveOptions(COMPUTE_AHEAD_BEHIND).tagRetrieveOptions(COMPUTE_AHEAD_BEHIND).baseReference(TagName.of("blah-no")).build())).isInstanceOf(ReferenceNotFoundException.class).hasMessage("Named reference 'blah-no' not found"), () -> assertThatThrownBy(() -> databaseAdapter.namedRefs(GetNamedRefsParams.builder().branchRetrieveOptions(RetrieveOptions.OMIT).tagRetrieveOptions(RetrieveOptions.OMIT).build())).isInstanceOf(IllegalArgumentException.class).hasMessage("Must retrieve branches or tags or both."));
}
Also used : TagName(org.projectnessie.versioned.TagName) BranchName(org.projectnessie.versioned.BranchName) Hash(org.projectnessie.versioned.Hash) Test(org.junit.jupiter.api.Test)

Example 10 with Hash

use of org.projectnessie.versioned.Hash in project nessie by projectnessie.

the class AbstractGlobalStates method commitCheckGlobalStateMismatches.

@Test
void commitCheckGlobalStateMismatches() throws Exception {
    BranchName branch = BranchName.of("main");
    Hash branchInitial = databaseAdapter.hashOnReference(branch, Optional.empty());
    databaseAdapter.commit(ImmutableCommitAttempt.builder().commitToBranch(branch).commitMetaSerialized(ByteString.EMPTY).addPuts(KeyWithBytes.of(Key.of("my", "table", "num0"), ContentId.of("id-0"), (byte) 0, ByteString.copyFromUtf8("there"))).putGlobal(ContentId.of("id-0"), ByteString.copyFromUtf8("global")).build());
    assertThatThrownBy(() -> databaseAdapter.commit(ImmutableCommitAttempt.builder().commitToBranch(branch).expectedHead(Optional.of(branchInitial)).commitMetaSerialized(ByteString.EMPTY).addPuts(KeyWithBytes.of(Key.of("my", "table", "num0"), ContentId.of("id-0"), (byte) 0, ByteString.copyFromUtf8("no no"))).putGlobal(ContentId.of("id-0"), ByteString.copyFromUtf8("no no")).putExpectedStates(ContentId.of("id-0"), Optional.empty()).build())).isInstanceOf(ReferenceConflictException.class).hasMessageContaining("Key 'my.table.num0' has conflicting put-operation from another commit.");
    assertThatThrownBy(() -> databaseAdapter.commit(ImmutableCommitAttempt.builder().commitToBranch(branch).commitMetaSerialized(ByteString.EMPTY).addPuts(KeyWithBytes.of(Key.of("my", "table", "num0"), ContentId.of("id-0"), (byte) 0, ByteString.copyFromUtf8("no no"))).putGlobal(ContentId.of("id-0"), ByteString.copyFromUtf8("DUPLICATE")).putExpectedStates(ContentId.of("id-0"), Optional.empty()).build())).isInstanceOf(ReferenceConflictException.class).hasMessageContaining("Global-state for content-id 'id-0' already exists.");
    assertThatThrownBy(() -> databaseAdapter.commit(ImmutableCommitAttempt.builder().commitToBranch(branch).commitMetaSerialized(ByteString.EMPTY).addPuts(KeyWithBytes.of(Key.of("my", "table", "num0"), ContentId.of("id-0"), (byte) 0, ByteString.copyFromUtf8("no no"))).putGlobal(ContentId.of("id-0"), ByteString.copyFromUtf8("DUPLICATE")).putExpectedStates(ContentId.of("id-0"), Optional.of(ByteString.copyFromUtf8("NOT THIS"))).build())).isInstanceOf(ReferenceConflictException.class).hasMessageContaining("Mismatch in global-state for content-id 'id-0'.");
    assertThatThrownBy(() -> databaseAdapter.commit(ImmutableCommitAttempt.builder().commitToBranch(branch).expectedHead(Optional.of(branchInitial)).commitMetaSerialized(ByteString.EMPTY).addPuts(KeyWithBytes.of(Key.of("my", "table", "num0"), ContentId.of("id-NOPE"), (byte) 0, ByteString.copyFromUtf8("no no"))).putGlobal(ContentId.of("id-NOPE"), ByteString.copyFromUtf8("DUPLICATE")).putExpectedStates(ContentId.of("id-NOPE"), Optional.of(ByteString.copyFromUtf8("NOT THIS"))).build())).isInstanceOf(ReferenceConflictException.class).hasMessageContaining("No current global-state for content-id 'id-NOPE'.");
}
Also used : ReferenceConflictException(org.projectnessie.versioned.ReferenceConflictException) BranchName(org.projectnessie.versioned.BranchName) Hash(org.projectnessie.versioned.Hash) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Aggregations

Hash (org.projectnessie.versioned.Hash)99 BranchName (org.projectnessie.versioned.BranchName)49 DatabaseAdapterUtil.randomHash (org.projectnessie.versioned.persist.adapter.spi.DatabaseAdapterUtil.randomHash)44 ReferenceConflictException (org.projectnessie.versioned.ReferenceConflictException)36 Test (org.junit.jupiter.api.Test)33 DatabaseAdapterUtil.verifyExpectedHash (org.projectnessie.versioned.persist.adapter.spi.DatabaseAdapterUtil.verifyExpectedHash)30 ByteString (com.google.protobuf.ByteString)28 ReferenceNotFoundException (org.projectnessie.versioned.ReferenceNotFoundException)27 Key (org.projectnessie.versioned.Key)25 CommitLogEntry (org.projectnessie.versioned.persist.adapter.CommitLogEntry)23 ArrayList (java.util.ArrayList)20 RefLogNotFoundException (org.projectnessie.versioned.RefLogNotFoundException)20 Stream (java.util.stream.Stream)19 Collectors (java.util.stream.Collectors)17 TagName (org.projectnessie.versioned.TagName)17 HashMap (java.util.HashMap)16 Optional (java.util.Optional)16 ReferenceAlreadyExistsException (org.projectnessie.versioned.ReferenceAlreadyExistsException)16 ReferenceInfo (org.projectnessie.versioned.ReferenceInfo)16 Collections (java.util.Collections)15