Skip to content

Commit

Permalink
Multy talbe test
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexander Lavrukov authored and nvamelichev committed Dec 27, 2024
1 parent 6e9c6ab commit 0fbaf0d
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public InMemoryTable(InMemoryRepositoryTransaction transaction, Class<T> type) {

public InMemoryTable(InMemoryRepositoryTransaction transaction, TableDescriptor<T> tableDescriptor) {
this.schema = EntitySchema.of(tableDescriptor.entityType());
this.tableDescriptor = TableDescriptor.from(schema);
this.tableDescriptor = tableDescriptor;
this.transaction = transaction;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1363,6 +1363,29 @@ public void testUniqueIndex() {
assertThrows(EntityAlreadyExistsException.class, () -> db.tx(() -> db.table(UniqueProject.class).save(ue2)));
}

@Test
public void testUsingSecondTable() {
String verySameName = "valuableName";
UniqueProject ue1 = new UniqueProject(new UniqueProject.Id("id1"), verySameName, 1);
db.tx(() -> {
db.table(UniqueProject.class).save(ue1);
db.table(TestEntities.SECOND_UNIQUE_PROJECT_TABLE).save(ue1.withVersion(2));
});
UniqueProject firstTableProject = db.tx(() -> db.table(UniqueProject.class).find(ue1.getId()));
UniqueProject secondTableProject = db.tx(() -> db.table(TestEntities.SECOND_UNIQUE_PROJECT_TABLE).find(ue1.getId()));

assertThat(firstTableProject.getVersion()).isEqualTo(1);
assertThat(secondTableProject.getVersion()).isEqualTo(2);

db.tx(() -> db.table(UniqueProject.class).delete(ue1.getId()));

firstTableProject = db.tx(() -> db.table(UniqueProject.class).find(ue1.getId()));
secondTableProject = db.tx(() -> db.table(TestEntities.SECOND_UNIQUE_PROJECT_TABLE).find(ue1.getId()));

assertThat(firstTableProject).isNull();
assertThat(secondTableProject.getVersion()).isEqualTo(2);
}

@Test
public void doubleTxIsOk() {
db.tx(this::findRange);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import lombok.NonNull;
import tech.ydb.yoj.repository.db.Entity;
import tech.ydb.yoj.repository.db.Repository;
import tech.ydb.yoj.repository.db.TableDescriptor;
import tech.ydb.yoj.repository.test.sample.model.Book;
import tech.ydb.yoj.repository.test.sample.model.Bubble;
import tech.ydb.yoj.repository.test.sample.model.BytePkEntity;
Expand Down Expand Up @@ -30,6 +31,10 @@
import java.util.List;

public final class TestEntities {
public static final TableDescriptor<UniqueProject> SECOND_UNIQUE_PROJECT_TABLE = new TableDescriptor<>(
UniqueProject.class, "second_uniq_project_table"
);

private TestEntities() {
}

Expand All @@ -54,11 +59,20 @@ private TestEntities() {
MultiWrappedEntity.class
);

public static final List<TableDescriptor<?>> ALL_TABLE_DESCRIPTORS = List.of(
SECOND_UNIQUE_PROJECT_TABLE
);


@SuppressWarnings("unchecked")
public static Repository init(@NonNull Repository repository) {
repository.createTablespace();
ALL.forEach(entityClass -> repository.schema(entityClass).create());

for (TableDescriptor<?> tableDescriptor : ALL_TABLE_DESCRIPTORS) {
repository.schema(tableDescriptor).create();
}

return repository;
}
}

0 comments on commit 0fbaf0d

Please sign in to comment.