Search in sources :

Example 1 with Operations

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

the class AbstractSparkSqlTest method commitAndReturnLog.

private List<Object[]> commitAndReturnLog(String branch) throws NessieConflictException, NessieNotFoundException {
    assertThat(sql("CREATE BRANCH %s IN nessie", branch)).containsExactly(row("Branch", branch, hash));
    ContentKey key = ContentKey.of("table", "name");
    CommitMeta cm1 = ImmutableCommitMeta.builder().author("sue").authorTime(Instant.ofEpochMilli(1)).message("1").putProperties("test", "123").build();
    CommitMeta cm2 = ImmutableCommitMeta.builder().author("janet").authorTime(Instant.ofEpochMilli(10)).message("2").putProperties("test", "123").build();
    CommitMeta cm3 = ImmutableCommitMeta.builder().author("alice").authorTime(Instant.ofEpochMilli(100)).message("3").putProperties("test", "123").build();
    Operations ops = ImmutableOperations.builder().addOperations(Operation.Put.of(key, IcebergTable.of("foo", 42, 42, 42, 42))).commitMeta(cm1).build();
    Operations ops2 = ImmutableOperations.builder().addOperations(Operation.Put.of(key, IcebergTable.of("bar", 42, 42, 42, 42))).commitMeta(cm2).build();
    Operations ops3 = ImmutableOperations.builder().addOperations(Operation.Put.of(key, IcebergTable.of("baz", 42, 42, 42, 42))).commitMeta(cm3).build();
    Branch ref1 = api.commitMultipleOperations().branchName(branch).hash(hash).operations(ops.getOperations()).commitMeta(ops.getCommitMeta()).commit();
    Branch ref2 = api.commitMultipleOperations().branchName(branch).hash(ref1.getHash()).operations(ops2.getOperations()).commitMeta(ops2.getCommitMeta()).commit();
    Branch ref3 = api.commitMultipleOperations().branchName(branch).hash(ref2.getHash()).operations(ops3.getOperations()).commitMeta(ops3.getCommitMeta()).commit();
    List<Object[]> resultList = new ArrayList<>();
    resultList.add(cmToRow(cm3, ref3.getHash()));
    resultList.add(cmToRow(cm2, ref2.getHash()));
    resultList.add(cmToRow(cm1, ref1.getHash()));
    return resultList;
}
Also used : ContentKey(org.projectnessie.model.ContentKey) Branch(org.projectnessie.model.Branch) ArrayList(java.util.ArrayList) ImmutableCommitMeta(org.projectnessie.model.ImmutableCommitMeta) CommitMeta(org.projectnessie.model.CommitMeta) ImmutableOperations(org.projectnessie.model.ImmutableOperations) Operations(org.projectnessie.model.Operations)

Example 2 with Operations

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

the class AbstractResteasyTest method testBasic.

@Test
public void testBasic() {
    int preSize = rest().get("trees").then().statusCode(200).extract().as(ReferencesResponse.class).getReferences().size();
    rest().get("trees/tree/mainx").then().statusCode(404);
    rest().body(Branch.of("mainx", null)).post("trees/tree").then().statusCode(200);
    ReferencesResponse references = rest().get("trees").then().statusCode(200).extract().as(ReferencesResponse.class);
    Assertions.assertEquals(preSize + 1, references.getReferences().size());
    Reference reference = rest().get("trees/tree/mainx").then().statusCode(200).extract().as(Reference.class);
    assertEquals("mainx", reference.getName());
    Branch newReference = ImmutableBranch.builder().hash(reference.getHash()).name("test").build();
    rest().queryParam("expectedHash", reference.getHash()).body(Branch.of("test", null)).post("trees/tree").then().statusCode(200);
    assertEquals(newReference, rest().get("trees/tree/test").then().statusCode(200).extract().as(Branch.class));
    IcebergTable table = IcebergTable.of("/the/directory/over/there", 42, 42, 42, 42);
    Branch commitResponse = rest().body(ImmutableOperations.builder().addOperations(ImmutablePut.builder().key(ContentKey.of("xxx", "test")).content(table).build()).commitMeta(CommitMeta.fromMessage("")).build()).queryParam("expectedHash", newReference.getHash()).post("trees/branch/{branch}/commit", newReference.getName()).then().statusCode(200).extract().as(Branch.class);
    Assertions.assertNotEquals(newReference.getHash(), commitResponse.getHash());
    Put[] updates = new Put[11];
    for (int i = 0; i < 10; i++) {
        updates[i] = ImmutablePut.builder().key(ContentKey.of("item", Integer.toString(i))).content(IcebergTable.of("/the/directory/over/there/" + i, 42, 42, 42, 42)).build();
    }
    updates[10] = ImmutablePut.builder().key(ContentKey.of("xxx", "test")).content(IcebergTable.of("/the/directory/over/there/has/been/moved", 42, 42, 42, 42)).build();
    Reference branch = rest().get("trees/tree/test").as(Reference.class);
    Operations contents = ImmutableOperations.builder().addOperations(updates).commitMeta(CommitMeta.fromMessage("")).build();
    commitResponse = rest().body(contents).queryParam("expectedHash", branch.getHash()).post("trees/branch/{branch}/commit", branch.getName()).then().statusCode(200).extract().as(Branch.class);
    Assertions.assertNotEquals(branch.getHash(), commitResponse.getHash());
    Response res = rest().queryParam("ref", "test").get("contents/xxx.test").then().extract().response();
    Assertions.assertEquals(updates[10].getContent(), res.body().as(Content.class));
    IcebergTable currentTable = table;
    table = IcebergTable.of("/the/directory/over/there/has/been/moved/again", 42, 42, 42, 42, table.getId());
    Branch b2 = rest().get("trees/tree/test").as(Branch.class);
    rest().body(ImmutableOperations.builder().addOperations(ImmutablePut.builder().key(ContentKey.of("xxx", "test")).content(table).expectedContent(currentTable).build()).commitMeta(CommitMeta.fromMessage("")).build()).queryParam("expectedHash", b2.getHash()).post("trees/branch/{branch}/commit", b2.getName()).then().statusCode(200).extract().as(Branch.class);
    Content returned = rest().queryParam("ref", "test").get("contents/xxx.test").then().statusCode(200).extract().as(Content.class);
    Assertions.assertEquals(table, returned);
    Branch b3 = rest().get("trees/tree/test").as(Branch.class);
    rest().body(Tag.of("tagtest", b3.getHash())).queryParam("sourceRefName", b3.getName()).post("trees/tree").then().statusCode(200);
    assertThat(rest().get("trees/tree/tagtest").then().statusCode(200).extract().body().as(Tag.class).getHash()).isEqualTo(b3.getHash());
    rest().queryParam("expectedHash", "0011223344556677889900112233445566778899001122334455667788990011".substring(0, b2.getHash().length())).delete("trees/tag/tagtest").then().statusCode(409);
    rest().queryParam("expectedHash", b3.getHash()).delete("trees/tag/tagtest").then().statusCode(204);
    LogResponse log = rest().get("trees/tree/test/log").then().statusCode(200).extract().as(LogResponse.class);
    Assertions.assertEquals(3, log.getLogEntries().size());
    Branch b1 = rest().get("trees/tree/test").as(Branch.class);
    rest().queryParam("expectedHash", b1.getHash()).delete("trees/branch/test").then().statusCode(204);
    Branch bx = rest().get("trees/tree/mainx").as(Branch.class);
    rest().queryParam("expectedHash", bx.getHash()).delete("trees/branch/mainx").then().statusCode(204);
}
Also used : LogResponse(org.projectnessie.model.LogResponse) RefLogResponse(org.projectnessie.model.RefLogResponse) ReferencesResponse(org.projectnessie.model.ReferencesResponse) Response(io.restassured.response.Response) DiffResponse(org.projectnessie.model.DiffResponse) LogResponse(org.projectnessie.model.LogResponse) RefLogResponse(org.projectnessie.model.RefLogResponse) Reference(org.projectnessie.model.Reference) ImmutableBranch(org.projectnessie.model.ImmutableBranch) Branch(org.projectnessie.model.Branch) Content(org.projectnessie.model.Content) IcebergTable(org.projectnessie.model.IcebergTable) ReferencesResponse(org.projectnessie.model.ReferencesResponse) Tag(org.projectnessie.model.Tag) ImmutableOperations(org.projectnessie.model.ImmutableOperations) Operations(org.projectnessie.model.Operations) Put(org.projectnessie.model.Operation.Put) ImmutablePut(org.projectnessie.model.ImmutablePut) Test(org.junit.jupiter.api.Test)

Aggregations

Branch (org.projectnessie.model.Branch)2 ImmutableOperations (org.projectnessie.model.ImmutableOperations)2 Operations (org.projectnessie.model.Operations)2 Response (io.restassured.response.Response)1 ArrayList (java.util.ArrayList)1 Test (org.junit.jupiter.api.Test)1 CommitMeta (org.projectnessie.model.CommitMeta)1 Content (org.projectnessie.model.Content)1 ContentKey (org.projectnessie.model.ContentKey)1 DiffResponse (org.projectnessie.model.DiffResponse)1 IcebergTable (org.projectnessie.model.IcebergTable)1 ImmutableBranch (org.projectnessie.model.ImmutableBranch)1 ImmutableCommitMeta (org.projectnessie.model.ImmutableCommitMeta)1 ImmutablePut (org.projectnessie.model.ImmutablePut)1 LogResponse (org.projectnessie.model.LogResponse)1 Put (org.projectnessie.model.Operation.Put)1 RefLogResponse (org.projectnessie.model.RefLogResponse)1 Reference (org.projectnessie.model.Reference)1 ReferencesResponse (org.projectnessie.model.ReferencesResponse)1 Tag (org.projectnessie.model.Tag)1