Search in sources :

Example 41 with Branch

use of org.projectnessie.model.Branch in project nessie by projectnessie.

the class AbstractTestBasicOperations method testAdmin.

@Test
@TestSecurity(user = "admin_user", roles = { "admin", "user" })
void testAdmin() throws BaseNessieClientServerException {
    getCatalog("testx");
    Branch branch = (Branch) api.getReference().refName("testx").get();
    List<Entry> tables = api.getEntries().refName("testx").get().getEntries();
    Assertions.assertTrue(tables.isEmpty());
    ContentKey key = ContentKey.of("x", "x");
    tryEndpointPass(() -> api.commitMultipleOperations().branch(branch).operation(Put.of(key, IcebergTable.of("foo", 42, 42, 42, 42, "cid-foo"))).commitMeta(CommitMeta.fromMessage("empty message")).commit());
    Assertions.assertTrue(api.getContent().refName("testx").key(key).get().get(key).unwrap(IcebergTable.class).isPresent());
    Branch master = (Branch) api.getReference().refName("testx").get();
    Branch test = Branch.of("testy", master.getHash());
    tryEndpointPass(() -> api.createReference().sourceRefName(master.getName()).reference(test).create());
    Branch test2 = (Branch) api.getReference().refName("testy").get();
    tryEndpointPass(() -> api.deleteBranch().branch(test2).delete());
    tryEndpointPass(() -> api.commitMultipleOperations().branch(master).operation(Delete.of(key)).commitMeta(CommitMeta.fromMessage("")).commit());
    assertThat(api.getContent().refName("testx").key(key).get()).isEmpty();
    tryEndpointPass(() -> {
        Branch b = (Branch) api.getReference().refName(branch.getName()).get();
        // Note: the initial version-store implementations just committed this operation, but it
        // should actually fail, because the operations of the 1st commit above and this commit
        // have conflicts.
        api.commitMultipleOperations().branch(b).operation(Put.of(key, IcebergTable.of("bar", 42, 42, 42, 42, "cid-bar"))).commitMeta(CommitMeta.fromMessage("")).commit();
    });
}
Also used : ContentKey(org.projectnessie.model.ContentKey) Entry(org.projectnessie.model.EntriesResponse.Entry) Branch(org.projectnessie.model.Branch) TestSecurity(io.quarkus.test.security.TestSecurity) Test(org.junit.jupiter.api.Test)

Example 42 with Branch

use of org.projectnessie.model.Branch in project nessie by projectnessie.

the class AbstractTestBasicOperations method testUserCleanup.

@Test
@TestSecurity(authorizationEnabled = false)
void testUserCleanup() throws BaseNessieClientServerException {
    getCatalog(null);
    Branch r = (Branch) api.getReference().refName("testx").get();
    api.deleteBranch().branch(r).delete();
}
Also used : Branch(org.projectnessie.model.Branch) TestSecurity(io.quarkus.test.security.TestSecurity) Test(org.junit.jupiter.api.Test)

Example 43 with Branch

use of org.projectnessie.model.Branch in project nessie by projectnessie.

the class AbstractCompatibilityTests method commit.

@Test
void commit() throws Exception {
    Branch defaultBranch = api.getDefaultBranch();
    Branch branch = Branch.of("commitToBranch", defaultBranch.getHash());
    Reference created = api.createReference().sourceRefName(defaultBranch.getName()).reference(branch).create();
    assertThat(created).isEqualTo(branch);
    ContentKey key = ContentKey.of("my", "tables", "table_name");
    IcebergTable content = IcebergTable.of("metadata-location", 42L, 43, 44, 45, "content-id");
    String commitMessage = "hello world";
    Put operation = Put.of(key, content);
    Branch branchNew = api.commitMultipleOperations().commitMeta(CommitMeta.fromMessage(commitMessage)).operation(operation).branch(branch).commit();
    assertThat(branchNew).isNotEqualTo(branch).extracting(Branch::getName).isEqualTo(branch.getName());
    LogResponse commitLog = api.getCommitLog().refName(branch.getName()).get();
    assertThat(commitLog.getLogEntries()).hasSize(1).map(LogEntry::getCommitMeta).map(CommitMeta::getMessage).containsExactly(commitMessage);
}
Also used : ContentKey(org.projectnessie.model.ContentKey) LogResponse(org.projectnessie.model.LogResponse) Branch(org.projectnessie.model.Branch) Reference(org.projectnessie.model.Reference) IcebergTable(org.projectnessie.model.IcebergTable) Put(org.projectnessie.model.Operation.Put) LogEntry(org.projectnessie.model.LogResponse.LogEntry) Test(org.junit.jupiter.api.Test)

Example 44 with Branch

use of org.projectnessie.model.Branch in project nessie by projectnessie.

the class AbstractRestGC method fillExpectedContents.

void fillExpectedContents(Branch branch, int numCommits, IdentifiedResult expected) throws NessieNotFoundException {
    fetchLogEntries(branch, numCommits).stream().map(LogEntry::getOperations).filter(Objects::nonNull).flatMap(Collection::stream).filter(op -> op instanceof Put).forEach(op -> {
        Content content = ((Put) op).getContent();
        expected.addContent(branch.getName(), content);
    });
}
Also used : Put(org.projectnessie.model.Operation.Put) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) HashMap(java.util.HashMap) Reference(org.projectnessie.model.Reference) NessieConflictException(org.projectnessie.error.NessieConflictException) ArrayList(java.util.ArrayList) Duration(java.time.Duration) Map(java.util.Map) Content(org.projectnessie.model.Content) CommitMeta(org.projectnessie.model.CommitMeta) SparkSession(org.apache.spark.sql.SparkSession) Operation(org.projectnessie.model.Operation) ImmutableMap(com.google.common.collect.ImmutableMap) Collection(java.util.Collection) Branch(org.projectnessie.model.Branch) LogEntry(org.projectnessie.model.LogResponse.LogEntry) Instant(java.time.Instant) NotNull(javax.validation.constraints.NotNull) Objects(java.util.Objects) List(java.util.List) FetchOption(org.projectnessie.api.params.FetchOption) IcebergView(org.projectnessie.model.IcebergView) IcebergTable(org.projectnessie.model.IcebergTable) CONF_NESSIE_URI(org.projectnessie.client.NessieConfigConstants.CONF_NESSIE_URI) AbstractRest(org.projectnessie.jaxrs.AbstractRest) ContentKey(org.projectnessie.model.ContentKey) Comparator(java.util.Comparator) CommitMultipleOperationsBuilder(org.projectnessie.client.api.CommitMultipleOperationsBuilder) NessieNotFoundException(org.projectnessie.error.NessieNotFoundException) Content(org.projectnessie.model.Content) Collection(java.util.Collection) LogEntry(org.projectnessie.model.LogResponse.LogEntry) Put(org.projectnessie.model.Operation.Put)

Example 45 with Branch

use of org.projectnessie.model.Branch in project nessie by projectnessie.

the class AbstractRestGCTest method testSingleRefDropRefBeforeCutoff.

@Test
public void testSingleRefDropRefBeforeCutoff() throws BaseNessieClientServerException {
    // ------  Time ---- | ---------- branch1 ------------------|
    // t0        |            create branch
    // t1        |            TABLE_ONE : 42 (expired)
    // t2        |            TABLE_TWO : 42 (expired)
    // t3        |            TABLE_TWO : 43 (expired)
    // t4        |            delete branch
    // t5        | ------- cut off time ----------------|
    String prefix = "singleRefDropRefBeforeCutoff";
    IdentifiedResult expectedResult = new IdentifiedResult();
    Branch branch1 = createBranch(prefix);
    // one commit for TABLE_ONE on branch1
    CommitOutput table1 = commitSingleOp(prefix, branch1, branch1.getHash(), 42, CID_ONE, TABLE_ONE, METADATA_ONE, null, null);
    // two commits for TABLE_TWO on branch1
    CommitOutput table2 = commitSingleOp(prefix, branch1, branch1.getHash(), 42, CID_TWO, TABLE_TWO, METADATA_ONE, null, null);
    // one commit for TABLE_TWO on branch1
    table2 = commitSingleOp(prefix, branch1, table2.hash, 43, CID_TWO, TABLE_TWO, METADATA_TWO, table2.content, null);
    // all 3 commits on branch1 are expected to be expired due to drop reference before cutoff time.
    fillExpectedContents(Branch.of(branch1.getName(), table2.hash), 3, expectedResult);
    // delete branch before cutoff time
    deleteBranch(branch1.getName(), table2.hash);
    final Instant cutoffTime = Instant.now();
    performGc(cutoffTime, null, expectedResult, Collections.singletonList(branch1.getName()), true, null);
}
Also used : Branch(org.projectnessie.model.Branch) Instant(java.time.Instant) Test(org.junit.jupiter.api.Test)

Aggregations

Branch (org.projectnessie.model.Branch)81 Test (org.junit.jupiter.api.Test)56 IcebergTable (org.projectnessie.model.IcebergTable)30 ContentKey (org.projectnessie.model.ContentKey)29 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)27 LogResponse (org.projectnessie.model.LogResponse)19 Reference (org.projectnessie.model.Reference)19 CommitMeta (org.projectnessie.model.CommitMeta)18 Instant (java.time.Instant)16 LogEntry (org.projectnessie.model.LogResponse.LogEntry)13 List (java.util.List)12 BaseNessieClientServerException (org.projectnessie.error.BaseNessieClientServerException)12 Tag (org.projectnessie.model.Tag)12 Collectors (java.util.stream.Collectors)11 NessieNotFoundException (org.projectnessie.error.NessieNotFoundException)11 Content (org.projectnessie.model.Content)11 Entry (org.projectnessie.model.EntriesResponse.Entry)10 Put (org.projectnessie.model.Operation.Put)10 IcebergView (org.projectnessie.model.IcebergView)9 Map (java.util.Map)8