Search in sources :

Example 16 with Key

use of org.projectnessie.versioned.Key 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 17 with Key

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

the class AbstractCommits method commitSomeOperations.

/*
   * Test:
   * - Create a new branch
   * - Add 3 commits in succession with no conflicts to it with put and delete operations
   * - Check commit metadata
   * - Check keys for each commit hash
   * - Check values for each commit hash
   */
@Test
public void commitSomeOperations() 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 secondCommit = commit("Second Commit").put("t1", V_1_2).delete("t2").delete("t3").put("t4", V_4_1).toBranch(branch);
    final Hash thirdCommit = commit("Third Commit").put("t2", V_2_2).unchanged("t4").toBranch(branch);
    assertThat(commitsList(branch, false)).contains(commit(thirdCommit, "Third Commit"), commit(secondCommit, "Second 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("t4"));
    }
    try (Stream<Key> keys = store().getKeys(secondCommit).map(WithType::getValue)) {
        assertThat(keys).containsExactlyInAnyOrder(Key.of("t1"), Key.of("t4"));
    }
    try (Stream<Key> keys = store().getKeys(initialCommit).map(WithType::getValue)) {
        assertThat(keys).containsExactlyInAnyOrder(Key.of("t1"), Key.of("t2"), Key.of("t3"));
    }
    assertThat(store().getValues(secondCommit, Arrays.asList(Key.of("t1"), Key.of("t2"), Key.of("t3"), Key.of("t4")))).containsExactlyInAnyOrderEntriesOf(ImmutableMap.of(Key.of("t1"), V_1_2, Key.of("t4"), V_4_1));
    assertThat(store().getValues(initialCommit, Arrays.asList(Key.of("t1"), Key.of("t2"), Key.of("t3"), Key.of("t4")))).containsExactlyInAnyOrderEntriesOf(ImmutableMap.of(Key.of("t1"), V_1_1, Key.of("t2"), V_2_1, Key.of("t3"), V_3_1));
    assertThat(store().getValue(branch, Key.of("t1"))).isEqualTo(V_1_2);
    assertThat(store().getValue(branch, Key.of("t2"))).isEqualTo(V_2_2);
    assertThat(store().getValue(branch, Key.of("t3"))).isNull();
    assertThat(store().getValue(branch, Key.of("t4"))).isEqualTo(V_4_1);
    assertThat(store().getValue(secondCommit, Key.of("t1"))).isEqualTo(V_1_2);
    assertThat(store().getValue(secondCommit, Key.of("t2"))).isNull();
    assertThat(store().getValue(secondCommit, Key.of("t3"))).isNull();
    assertThat(store().getValue(secondCommit, Key.of("t4"))).isEqualTo(V_4_1);
    assertThat(store().getValue(initialCommit, Key.of("t1"))).isEqualTo(V_1_1);
    assertThat(store().getValue(initialCommit, Key.of("t2"))).isEqualTo(V_2_1);
    assertThat(store().getValue(initialCommit, Key.of("t3"))).isEqualTo(V_3_1);
    assertThat(store().getValue(initialCommit, Key.of("t4"))).isNull();
}
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 18 with Key

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

the class AbstractMerge method mergeWithConflictingKeys.

@Test
protected void mergeWithConflictingKeys() throws VersionStoreException {
    final BranchName foo = BranchName.of("foofoo");
    final BranchName bar = BranchName.of("barbar");
    store().create(foo, Optional.of(this.initialHash));
    store().create(bar, Optional.of(this.initialHash));
    // we're essentially modifying the same key on both branches and then merging one branch into
    // the other and expect a conflict
    Key key1 = Key.of("some_key1");
    Key key2 = Key.of("some_key2");
    store().commit(foo, Optional.empty(), commitMessage("commit 1"), Collections.singletonList(Put.of(key1, VALUE_1)));
    store().commit(bar, Optional.empty(), commitMessage("commit 2"), Collections.singletonList(Put.of(key1, VALUE_2)));
    store().commit(foo, Optional.empty(), commitMessage("commit 3"), Collections.singletonList(Put.of(key2, VALUE_3)));
    Hash barHash = store().commit(bar, Optional.empty(), commitMessage("commit 4"), Collections.singletonList(Put.of(key2, VALUE_4)));
    assertThatThrownBy(() -> store().merge(barHash, foo, Optional.empty(), Function.identity())).isInstanceOf(ReferenceConflictException.class).hasMessageContaining("The following keys have been changed in conflict:").hasMessageContaining(key1.toString()).hasMessageContaining(key2.toString());
}
Also used : ReferenceConflictException(org.projectnessie.versioned.ReferenceConflictException) BranchName(org.projectnessie.versioned.BranchName) Hash(org.projectnessie.versioned.Hash) Key(org.projectnessie.versioned.Key) Test(org.junit.jupiter.api.Test)

Example 19 with Key

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

the class AbstractMerge method nonEmptyFastForwardMerge.

@Test
protected void nonEmptyFastForwardMerge() throws VersionStoreException {
    final Key key = Key.of("t1");
    final BranchName etl = BranchName.of("etl");
    final BranchName review = BranchName.of("review");
    store().create(etl, Optional.of(initialHash));
    store().create(review, Optional.of(initialHash));
    store().commit(etl, Optional.empty(), commitMessage("commit 1"), Collections.singletonList(Put.of(key, VALUE_1)));
    store().merge(store().hashOnReference(etl, Optional.empty()), review, Optional.empty(), Function.identity());
    store().commit(etl, Optional.empty(), commitMessage("commit 2"), Collections.singletonList(Put.of(key, VALUE_2)));
    store().merge(store().hashOnReference(etl, Optional.empty()), review, Optional.empty(), Function.identity());
    assertEquals(store().getValue(review, key), VALUE_2);
}
Also used : BranchName(org.projectnessie.versioned.BranchName) Key(org.projectnessie.versioned.Key) Test(org.junit.jupiter.api.Test)

Example 20 with Key

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

the class TreeApiImpl method getEntries.

@Override
public EntriesResponse getEntries(String namedRef, EntriesParams params) throws NessieNotFoundException {
    Preconditions.checkArgument(params.pageToken() == null, "Paging not supported");
    WithHash<NamedRef> refWithHash = namedRefWithHashOrThrow(namedRef, params.hashOnRef());
    // all existing VersionStore implementations have to read all keys anyways so we don't get much
    try {
        List<EntriesResponse.Entry> entries;
        try (Stream<EntriesResponse.Entry> entryStream = getStore().getKeys(refWithHash.getHash()).map(key -> EntriesResponse.Entry.builder().name(fromKey(key.getValue())).type((Type) key.getType()).build())) {
            Stream<EntriesResponse.Entry> entriesStream = filterEntries(entryStream, params.filter());
            if (params.namespaceDepth() != null && params.namespaceDepth() > 0) {
                entriesStream = entriesStream.filter(e -> e.getName().getElements().size() >= params.namespaceDepth()).map(e -> truncate(e, params.namespaceDepth())).distinct();
            }
            entries = entriesStream.collect(ImmutableList.toImmutableList());
        }
        return EntriesResponse.builder().addAllEntries(entries).build();
    } catch (ReferenceNotFoundException e) {
        throw new NessieReferenceNotFoundException(e.getMessage(), e);
    }
}
Also used : Detached(org.projectnessie.model.Detached) TreeApi(org.projectnessie.api.TreeApi) ServerConfig(org.projectnessie.services.config.ServerConfig) VAR_REF_TYPE(org.projectnessie.services.cel.CELUtil.VAR_REF_TYPE) NessieReferenceNotFoundException(org.projectnessie.error.NessieReferenceNotFoundException) NessieConflictException(org.projectnessie.error.NessieConflictException) GetNamedRefsParams(org.projectnessie.versioned.GetNamedRefsParams) VAR_REF(org.projectnessie.services.cel.CELUtil.VAR_REF) VersionStore(org.projectnessie.versioned.VersionStore) Delete(org.projectnessie.versioned.Delete) Type(org.projectnessie.model.Content.Type) Map(java.util.Map) Content(org.projectnessie.model.Content) Ref(org.projectnessie.versioned.Ref) NamedRef(org.projectnessie.versioned.NamedRef) VAR_CONTENT_TYPE(org.projectnessie.services.cel.CELUtil.VAR_CONTENT_TYPE) ScriptException(org.projectnessie.cel.tools.ScriptException) ImmutableMap(com.google.common.collect.ImmutableMap) Validation(org.projectnessie.model.Validation) ReferencesResponse(org.projectnessie.model.ReferencesResponse) REFERENCES_DECLARATIONS(org.projectnessie.services.cel.CELUtil.REFERENCES_DECLARATIONS) Branch(org.projectnessie.model.Branch) LogEntry(org.projectnessie.model.LogResponse.LogEntry) ReferenceAlreadyExistsException(org.projectnessie.versioned.ReferenceAlreadyExistsException) EntriesResponse(org.projectnessie.model.EntriesResponse) COMMIT_LOG_TYPES(org.projectnessie.services.cel.CELUtil.COMMIT_LOG_TYPES) Collectors(java.util.stream.Collectors) Objects(java.util.Objects) BranchName(org.projectnessie.versioned.BranchName) ReferenceConflictException(org.projectnessie.versioned.ReferenceConflictException) List(java.util.List) Principal(java.security.Principal) Stream(java.util.stream.Stream) ENTRIES_DECLARATIONS(org.projectnessie.services.cel.CELUtil.ENTRIES_DECLARATIONS) Transplant(org.projectnessie.model.Transplant) ImmutableReferencesResponse(org.projectnessie.model.ImmutableReferencesResponse) Optional(java.util.Optional) ContentKey(org.projectnessie.model.ContentKey) CELUtil(org.projectnessie.services.cel.CELUtil) NessieNotFoundException(org.projectnessie.error.NessieNotFoundException) Put(org.projectnessie.versioned.Put) ReferenceMetadata(org.projectnessie.model.ReferenceMetadata) LogResponse(org.projectnessie.model.LogResponse) NessieReferenceAlreadyExistsException(org.projectnessie.error.NessieReferenceAlreadyExistsException) Authorizer(org.projectnessie.services.authz.Authorizer) VAR_ENTRY(org.projectnessie.services.cel.CELUtil.VAR_ENTRY) TagName(org.projectnessie.versioned.TagName) Reference(org.projectnessie.model.Reference) Strings(com.google.common.base.Strings) Script(org.projectnessie.cel.tools.Script) COMMIT_LOG_DECLARATIONS(org.projectnessie.services.cel.CELUtil.COMMIT_LOG_DECLARATIONS) ImmutableLogResponse(org.projectnessie.model.ImmutableLogResponse) ImmutableList(com.google.common.collect.ImmutableList) GetReferenceParams(org.projectnessie.api.params.GetReferenceParams) ReferencesParams(org.projectnessie.api.params.ReferencesParams) Merge(org.projectnessie.model.Merge) NessieReferenceConflictException(org.projectnessie.error.NessieReferenceConflictException) StreamSupport(java.util.stream.StreamSupport) CommitMeta(org.projectnessie.model.CommitMeta) ImmutableLogEntry(org.projectnessie.model.ImmutableLogEntry) Nullable(javax.annotation.Nullable) VAR_COMMIT(org.projectnessie.services.cel.CELUtil.VAR_COMMIT) WithHash(org.projectnessie.versioned.WithHash) Operation(org.projectnessie.model.Operation) REFERENCES_TYPES(org.projectnessie.services.cel.CELUtil.REFERENCES_TYPES) CommitLogParams(org.projectnessie.api.params.CommitLogParams) Hash(org.projectnessie.versioned.Hash) ImmutableTag(org.projectnessie.model.ImmutableTag) ImmutableBranch(org.projectnessie.model.ImmutableBranch) SCRIPT_HOST(org.projectnessie.services.cel.CELUtil.SCRIPT_HOST) Commit(org.projectnessie.versioned.Commit) ImmutableReferenceMetadata(org.projectnessie.model.ImmutableReferenceMetadata) CONTAINER(org.projectnessie.services.cel.CELUtil.CONTAINER) VAR_NAMESPACE(org.projectnessie.services.cel.CELUtil.VAR_NAMESPACE) Key(org.projectnessie.versioned.Key) ReferenceNotFoundException(org.projectnessie.versioned.ReferenceNotFoundException) VAR_REF_META(org.projectnessie.services.cel.CELUtil.VAR_REF_META) RetrieveOptions(org.projectnessie.versioned.GetNamedRefsParams.RetrieveOptions) EntriesParams(org.projectnessie.api.params.EntriesParams) FetchOption(org.projectnessie.api.params.FetchOption) Operations(org.projectnessie.model.Operations) ReferenceInfo(org.projectnessie.versioned.ReferenceInfo) Preconditions(com.google.common.base.Preconditions) RefUtil.toNamedRef(org.projectnessie.services.impl.RefUtil.toNamedRef) Collections(java.util.Collections) VAR_OPERATIONS(org.projectnessie.services.cel.CELUtil.VAR_OPERATIONS) Unchanged(org.projectnessie.versioned.Unchanged) LogEntry(org.projectnessie.model.LogResponse.LogEntry) ImmutableLogEntry(org.projectnessie.model.ImmutableLogEntry) NessieReferenceNotFoundException(org.projectnessie.error.NessieReferenceNotFoundException) ReferenceNotFoundException(org.projectnessie.versioned.ReferenceNotFoundException) NessieReferenceNotFoundException(org.projectnessie.error.NessieReferenceNotFoundException) NamedRef(org.projectnessie.versioned.NamedRef) RefUtil.toNamedRef(org.projectnessie.services.impl.RefUtil.toNamedRef)

Aggregations

Key (org.projectnessie.versioned.Key)29 BranchName (org.projectnessie.versioned.BranchName)21 Hash (org.projectnessie.versioned.Hash)21 ByteString (com.google.protobuf.ByteString)14 List (java.util.List)12 Collectors (java.util.stream.Collectors)12 Stream (java.util.stream.Stream)12 ReferenceConflictException (org.projectnessie.versioned.ReferenceConflictException)12 ArrayList (java.util.ArrayList)11 Map (java.util.Map)11 Optional (java.util.Optional)11 ReferenceNotFoundException (org.projectnessie.versioned.ReferenceNotFoundException)11 Test (org.junit.jupiter.api.Test)10 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)10 ContentId (org.projectnessie.versioned.persist.adapter.ContentId)10 IntStream (java.util.stream.IntStream)9 KeyWithBytes (org.projectnessie.versioned.persist.adapter.KeyWithBytes)9 Collections (java.util.Collections)8 ContentAndState (org.projectnessie.versioned.persist.adapter.ContentAndState)8 DatabaseAdapter (org.projectnessie.versioned.persist.adapter.DatabaseAdapter)8