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();
});
}
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();
}
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);
}
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);
});
}
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);
}
Aggregations