Search in sources :

Example 21 with BranchName

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

the class AbstractCommits method forceCommitConflictingOperations.

/*
   * Test:
   * - Create a new branch
   * - Add a commit to create 2 keys
   * - Add a second commit to delete one key and add a new one
   * - force commit put operations
   * - Check that put operations against 1st commit for the 3 keys fail
   * - Check that delete operations against 1st commit for the 3 keys fail
   * - Check that unchanged operations against 1st commit for the 3 keys fail
   * - Check that branch state hasn't changed
   */
@Test
public void forceCommitConflictingOperations() throws Exception {
    final BranchName branch = BranchName.of("foo");
    store().create(branch, Optional.empty());
    commit("Initial Commit").put("t1", V_1_1).put("t2", V_2_1).toBranch(branch);
    commit("Second Commit").put("t1", V_1_2).delete("t2").put("t3", V_3_1).toBranch(branch);
    final Hash putCommit = forceCommit("Conflicting Commit").put("t1", V_1_3).put("t2", V_2_2).put("t3", V_3_2).toBranch(branch);
    assertThat(store().hashOnReference(branch, Optional.empty())).isEqualTo(putCommit);
    assertThat(store().getValues(branch, Arrays.asList(Key.of("t1"), Key.of("t2"), Key.of("t3")))).containsExactlyInAnyOrderEntriesOf(ImmutableMap.of(Key.of("t1"), V_1_3, Key.of("t2"), V_2_2, Key.of("t3"), V_3_2));
    final Hash unchangedCommit = commit("Conflicting Commit").unchanged("t1").unchanged("t2").unchanged("t3").toBranch(branch);
    assertThat(store().hashOnReference(branch, Optional.empty())).isEqualTo(unchangedCommit);
    assertThat(store().getValues(branch, Arrays.asList(Key.of("t1"), Key.of("t2"), Key.of("t3")))).containsExactlyInAnyOrderEntriesOf(ImmutableMap.of(Key.of("t1"), V_1_3, Key.of("t2"), V_2_2, Key.of("t3"), V_3_2));
    final Hash deleteCommit = commit("Conflicting Commit").delete("t1").delete("t2").delete("t3").toBranch(branch);
    assertThat(store().hashOnReference(branch, Optional.empty())).isEqualTo(deleteCommit);
    assertThat(store().getValues(branch, Arrays.asList(Key.of("t1"), Key.of("t2"), Key.of("t3")))).isEmpty();
}
Also used : BranchName(org.projectnessie.versioned.BranchName) Hash(org.projectnessie.versioned.Hash) Test(org.junit.jupiter.api.Test)

Example 22 with BranchName

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

the class AbstractCommits method commitConflictingOperations.

/*
   * Test:
   * - Create a new branch
   * - Add a commit to create 2 keys
   * - Add a second commit to delete one key and add a new one
   * - Check that put operations against 1st commit for the 3 keys fail
   * - Check that delete operations against 1st commit for the 3 keys fail
   * - Check that unchanged operations against 1st commit for the 3 keys fail
   * - Check that branch state hasn't changed
   */
@Test
public void commitConflictingOperations() throws Exception {
    final BranchName branch = BranchName.of("foo");
    store().create(branch, Optional.empty());
    final Hash initialCommit = commit("Initial Commit").put("t1", V_1_1).put("t2", V_2_1).toBranch(branch);
    final Hash secondCommit = commit("Second Commit").put("t1", V_1_2).delete("t2").put("t3", V_3_1).toBranch(branch);
    assertThrows(ReferenceConflictException.class, () -> commit("Conflicting Commit").fromReference(initialCommit).put("t1", V_1_3).toBranch(branch));
    assertThrows(ReferenceConflictException.class, () -> commit("Conflicting Commit").fromReference(initialCommit).put("t2", V_2_2).toBranch(branch));
    assertThrows(ReferenceConflictException.class, () -> commit("Conflicting Commit").fromReference(initialCommit).put("t3", V_3_2).toBranch(branch));
    assertThrows(ReferenceConflictException.class, () -> commit("Conflicting Commit").fromReference(initialCommit).delete("t1").toBranch(branch));
    assertThrows(ReferenceConflictException.class, () -> commit("Conflicting Commit").fromReference(initialCommit).delete("t2").toBranch(branch));
    assertThrows(ReferenceConflictException.class, () -> commit("Conflicting Commit").fromReference(initialCommit).delete("t3").toBranch(branch));
    // Checking the state hasn't changed
    assertThat(store().hashOnReference(branch, Optional.empty())).isEqualTo(secondCommit);
}
Also used : BranchName(org.projectnessie.versioned.BranchName) Hash(org.projectnessie.versioned.Hash) Test(org.junit.jupiter.api.Test)

Example 23 with BranchName

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

the class AbstractCommits method commitWithUnknownReference.

/*
   * Test:
   * - Check that store throws RNFE if reference hash doesn't exist
   */
@Test
public void commitWithUnknownReference() throws ReferenceNotFoundException, ReferenceAlreadyExistsException {
    final BranchName branch = BranchName.of("foo");
    store().create(branch, Optional.empty());
    assertThrows(ReferenceNotFoundException.class, () -> store().commit(branch, Optional.of(Hash.of("1234567890abcdef")), commitMessage("New commit"), Collections.emptyList()));
}
Also used : BranchName(org.projectnessie.versioned.BranchName) Test(org.junit.jupiter.api.Test)

Example 24 with BranchName

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

the class AbstractCommits method commitNonConflictingOperations.

/*
   * Test:
   * - Create a new branch
   * - Add a commit for 3 keys
   * - Add a commit based on initial commit for first key
   * - Add a commit based on initial commit for second key
   * - Add a commit based on initial commit for third  key
   * - Check commit metadata
   * - Check keys for each commit hash
   * - Check values for each commit hash
   */
@Test
public void commitNonConflictingOperations() throws Exception {
    final BranchName branch = BranchName.of("foo");
    store().create(branch, Optional.empty());
    final Hash initialCommit = commit("Initial Commit").put("t1", V_1_1).put("t2", V_2_1).put("t3", V_3_1).toBranch(branch);
    final Hash t1Commit = commit("T1 Commit").fromReference(initialCommit).put("t1", V_1_2).toBranch(branch);
    final Hash t2Commit = commit("T2 Commit").fromReference(initialCommit).delete("t2").toBranch(branch);
    final Hash t3Commit = commit("T3 Commit").fromReference(initialCommit).unchanged("t3").toBranch(branch);
    final Hash extraCommit = commit("Extra Commit").fromReference(t1Commit).put("t1", V_1_3).put("t3", V_3_2).toBranch(branch);
    final Hash newT2Commit = commit("New T2 Commit").fromReference(t2Commit).put("t2", NEW_v2_1).toBranch(branch);
    assertThat(commitsList(branch, false)).contains(commit(newT2Commit, "New T2 Commit"), commit(extraCommit, "Extra Commit"), commit(t3Commit, "T3 Commit"), commit(t2Commit, "T2 Commit"), commit(t1Commit, "T1 Commit"), commit(initialCommit, "Initial Commit"));
    try (Stream<Key> keys = store().getKeys(branch).map(WithType::getValue)) {
        assertThat(keys).containsExactlyInAnyOrder(Key.of("t1"), Key.of("t2"), Key.of("t3"));
    }
    assertThat(store().getValues(branch, Arrays.asList(Key.of("t1"), Key.of("t2"), Key.of("t3")))).containsExactlyInAnyOrderEntriesOf(ImmutableMap.of(Key.of("t1"), V_1_3, Key.of("t2"), NEW_v2_1, Key.of("t3"), V_3_2));
    assertThat(store().getValues(newT2Commit, Arrays.asList(Key.of("t1"), Key.of("t2"), Key.of("t3")))).containsExactlyInAnyOrderEntriesOf(ImmutableMap.of(Key.of("t1"), V_1_3, Key.of("t2"), NEW_v2_1, Key.of("t3"), V_3_2));
    assertThat(store().getValues(extraCommit, Arrays.asList(Key.of("t1"), Key.of("t2"), Key.of("t3")))).containsExactlyInAnyOrderEntriesOf(ImmutableMap.of(Key.of("t1"), V_1_3, Key.of("t3"), V_3_2));
    assertThat(store().getValues(t3Commit, Arrays.asList(Key.of("t1"), Key.of("t2"), Key.of("t3")))).containsExactlyInAnyOrderEntriesOf(ImmutableMap.of(Key.of("t1"), V_1_2, Key.of("t3"), V_3_1));
    assertThat(store().getValues(t2Commit, Arrays.asList(Key.of("t1"), Key.of("t2"), Key.of("t3")))).containsExactlyInAnyOrderEntriesOf(ImmutableMap.of(Key.of("t1"), V_1_2, Key.of("t3"), V_3_1));
    assertThat(store().getValues(t1Commit, Arrays.asList(Key.of("t1"), Key.of("t2"), Key.of("t3")))).containsExactlyInAnyOrderEntriesOf(ImmutableMap.of(Key.of("t1"), V_1_2, Key.of("t2"), V_2_1, Key.of("t3"), V_3_1));
}
Also used : WithType(org.projectnessie.versioned.WithType) BranchName(org.projectnessie.versioned.BranchName) Hash(org.projectnessie.versioned.Hash) Key(org.projectnessie.versioned.Key) Test(org.junit.jupiter.api.Test)

Example 25 with BranchName

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

the class AbstractCommits method commitWithInvalidBranch.

/*
   * Test:
   * - Check that store throws RNFE if branch doesn't exist
   */
@Test
public void commitWithInvalidBranch() {
    final BranchName branch = BranchName.of("unknown");
    assertThrows(ReferenceNotFoundException.class, () -> store().commit(branch, Optional.empty(), commitMessage("New commit"), Collections.emptyList()));
}
Also used : BranchName(org.projectnessie.versioned.BranchName) Test(org.junit.jupiter.api.Test)

Aggregations

BranchName (org.projectnessie.versioned.BranchName)72 Test (org.junit.jupiter.api.Test)51 Hash (org.projectnessie.versioned.Hash)45 Key (org.projectnessie.versioned.Key)23 ReferenceConflictException (org.projectnessie.versioned.ReferenceConflictException)16 Stream (java.util.stream.Stream)14 ByteString (com.google.protobuf.ByteString)13 Optional (java.util.Optional)13 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)13 Collectors (java.util.stream.Collectors)12 IntStream (java.util.stream.IntStream)11 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)11 ImmutableCommitAttempt (org.projectnessie.versioned.persist.adapter.ImmutableCommitAttempt)11 List (java.util.List)10 ContentId (org.projectnessie.versioned.persist.adapter.ContentId)10 DatabaseAdapter (org.projectnessie.versioned.persist.adapter.DatabaseAdapter)10 KeyWithBytes (org.projectnessie.versioned.persist.adapter.KeyWithBytes)10 Collections (java.util.Collections)9 ReferenceNotFoundException (org.projectnessie.versioned.ReferenceNotFoundException)9 TagName (org.projectnessie.versioned.TagName)9