Search in sources :

Example 26 with MutableMetaSnapshot

use of com.torodb.core.transaction.metainf.MutableMetaSnapshot in project torodb by torodb.

the class SnapshotMergerTest method testField_different.

/**
   * Test that no exception is thrown when creating a new field with different id, name and type
   *
   * @throws Exception
   */
@Test
public void testField_different() throws Exception {
    MutableMetaSnapshot changedSnapshot = new WrapperMutableMetaSnapshot(new ImmutableMetaSnapshot(Collections.emptyMap()));
    changedSnapshot.addMetaDatabase("dbName1", "dbId1").addMetaCollection("colName1", "colId1").addMetaDocPart(tableRefFactory.createRoot(), "docPartId1").addMetaField("fieldName10", "fieldId20", FieldType.CHILD);
    new SnapshotMerger(currentSnapshot, changedSnapshot).merge();
}
Also used : WrapperMutableMetaSnapshot(com.torodb.core.transaction.metainf.WrapperMutableMetaSnapshot) MutableMetaSnapshot(com.torodb.core.transaction.metainf.MutableMetaSnapshot) ImmutableMetaSnapshot(com.torodb.core.transaction.metainf.ImmutableMetaSnapshot) WrapperMutableMetaSnapshot(com.torodb.core.transaction.metainf.WrapperMutableMetaSnapshot) Test(org.junit.Test)

Example 27 with MutableMetaSnapshot

use of com.torodb.core.transaction.metainf.MutableMetaSnapshot in project torodb by torodb.

the class SnapshotMergerTest method testScalarIdConflict.

/**
   * Test that an exception is thrown on scalar id conflicts
   *
   * @throws Exception
   */
@Test
public void testScalarIdConflict() throws Exception {
    MutableMetaSnapshot changedSnapshot = new WrapperMutableMetaSnapshot(new ImmutableMetaSnapshot(Collections.emptyMap()));
    changedSnapshot.addMetaDatabase("dbName1", "dbId1").addMetaCollection("colName1", "colId1").addMetaDocPart(tableRefFactory.createRoot(), "docPartId1").addMetaScalar("scalarId1", FieldType.LONG);
    try {
        new SnapshotMerger(currentSnapshot, changedSnapshot).merge();
        Assert.fail("A " + UnmergeableException.class.getSimpleName() + " was expected to be thrown");
    } catch (UnmergeableException ex) {
    }
}
Also used : WrapperMutableMetaSnapshot(com.torodb.core.transaction.metainf.WrapperMutableMetaSnapshot) MutableMetaSnapshot(com.torodb.core.transaction.metainf.MutableMetaSnapshot) UnmergeableException(com.torodb.core.transaction.metainf.UnmergeableException) ImmutableMetaSnapshot(com.torodb.core.transaction.metainf.ImmutableMetaSnapshot) WrapperMutableMetaSnapshot(com.torodb.core.transaction.metainf.WrapperMutableMetaSnapshot) Test(org.junit.Test)

Example 28 with MutableMetaSnapshot

use of com.torodb.core.transaction.metainf.MutableMetaSnapshot in project torodb by torodb.

the class SnapshotMergerTest method testField_differentType.

/**
   * Test that no exception is thrown when creating a new field that shares name but not type with a
   * previous one.
   *
   * @throws Exception
   */
@Test
public void testField_differentType() throws Exception {
    MutableMetaSnapshot changedSnapshot = new WrapperMutableMetaSnapshot(new ImmutableMetaSnapshot(Collections.emptyMap()));
    changedSnapshot.addMetaDatabase("dbName1", "dbId1").addMetaCollection("colName1", "colId1").addMetaDocPart(tableRefFactory.createRoot(), "docPartId1").addMetaField("fieldName1", "fieldId4", FieldType.TIME);
    new SnapshotMerger(currentSnapshot, changedSnapshot).merge();
}
Also used : WrapperMutableMetaSnapshot(com.torodb.core.transaction.metainf.WrapperMutableMetaSnapshot) MutableMetaSnapshot(com.torodb.core.transaction.metainf.MutableMetaSnapshot) ImmutableMetaSnapshot(com.torodb.core.transaction.metainf.ImmutableMetaSnapshot) WrapperMutableMetaSnapshot(com.torodb.core.transaction.metainf.WrapperMutableMetaSnapshot) Test(org.junit.Test)

Example 29 with MutableMetaSnapshot

use of com.torodb.core.transaction.metainf.MutableMetaSnapshot in project torodb by torodb.

the class SnapshotMergerForIndexTest method testIndexWithMultiFieldsInMultiDocPartsWithNewFieldAndNewDocPartIndex.

/**
   * Test new field with new doc part index for existing index with multiple fields in multiple doc
   * parts Case 3&3.OK1.3
   *
   * @throws Exception
   */
@Test
public void testIndexWithMultiFieldsInMultiDocPartsWithNewFieldAndNewDocPartIndex() throws Exception {
    MutableMetaSnapshot currentModifiedSnapshot = new WrapperMutableMetaSnapshot(currentSnapshot);
    currentModifiedSnapshot.getMetaDatabaseByName("dbName1").getMetaCollectionByName("colName1").addMetaIndex("idxName2", false).addMetaIndexField(tableRefFactory.createRoot(), "fieldName2", FieldIndexOrdering.ASC);
    currentModifiedSnapshot.getMetaDatabaseByName("dbName1").getMetaCollectionByName("colName1").getMetaIndexByName("idxName2").addMetaIndexField(tableRefFactory.createRoot(), "fieldName3", FieldIndexOrdering.ASC);
    currentModifiedSnapshot.getMetaDatabaseByName("dbName1").getMetaCollectionByName("colName1").addMetaDocPart(tableRefFactory.createChild(tableRefFactory.createRoot(), "docPartName2"), "docPartId2");
    currentModifiedSnapshot.getMetaDatabaseByName("dbName1").getMetaCollectionByName("colName1").getMetaIndexByName("idxName2").addMetaIndexField(tableRefFactory.createChild(tableRefFactory.createRoot(), "docPartName2"), "fieldName4", FieldIndexOrdering.ASC);
    currentModifiedSnapshot.getMetaDatabaseByName("dbName1").getMetaCollectionByName("colName1").getMetaIndexByName("idxName2").addMetaIndexField(tableRefFactory.createChild(tableRefFactory.createRoot(), "docPartName2"), "fieldName5", FieldIndexOrdering.ASC);
    currentModifiedSnapshot.getMetaDatabaseByName("dbName1").getMetaCollectionByName("colName1").getMetaDocPartByTableRef(tableRefFactory.createRoot()).addMetaField("fieldName2", "fieldId2", FieldType.STRING);
    MutableMetaSnapshot changedSnapshot = new WrapperMutableMetaSnapshot(currentModifiedSnapshot.immutableCopy());
    changedSnapshot.getMetaDatabaseByName("dbName1").getMetaCollectionByName("colName1").getMetaDocPartByTableRef(tableRefFactory.createRoot()).addMetaField("fieldName3", "fieldId3", FieldType.STRING);
    changedSnapshot.getMetaDatabaseByName("dbName1").getMetaCollectionByName("colName1").getMetaDocPartByTableRef(tableRefFactory.createRoot()).addMetaDocPartIndex(false).addMetaDocPartIndexColumn("fieldId2", FieldIndexOrdering.ASC);
    changedSnapshot.getMetaDatabaseByName("dbName1").getMetaCollectionByName("colName1").getMetaDocPartByTableRef(tableRefFactory.createRoot()).getAddedMutableMetaDocPartIndexes().iterator().next().addMetaDocPartIndexColumn("fieldId3", FieldIndexOrdering.ASC);
    changedSnapshot.getMetaDatabaseByName("dbName1").getMetaCollectionByName("colName1").getMetaDocPartByTableRef(tableRefFactory.createRoot()).getAddedMutableMetaDocPartIndexes().iterator().next().immutableCopy("idxId2");
    new SnapshotMerger(currentModifiedSnapshot.immutableCopy(), changedSnapshot).merge();
}
Also used : WrapperMutableMetaSnapshot(com.torodb.core.transaction.metainf.WrapperMutableMetaSnapshot) MutableMetaSnapshot(com.torodb.core.transaction.metainf.MutableMetaSnapshot) WrapperMutableMetaSnapshot(com.torodb.core.transaction.metainf.WrapperMutableMetaSnapshot) Test(org.junit.Test)

Example 30 with MutableMetaSnapshot

use of com.torodb.core.transaction.metainf.MutableMetaSnapshot in project torodb by torodb.

the class SnapshotMergerForIndexTest method testNewIndexWhichMatchOldIndexConflict.

/**
   * Test an exception is thrown when a new index match an old index Case 1&1.KO1.1a
   *
   * @throws Exception
   */
@Test
public void testNewIndexWhichMatchOldIndexConflict() throws Exception {
    MutableMetaSnapshot currentModifiedSnapshot = new WrapperMutableMetaSnapshot(currentSnapshot);
    currentModifiedSnapshot.getMetaDatabaseByName("dbName1").getMetaCollectionByName("colName1").addMetaIndex("idxName3", false).addMetaIndexField(tableRefFactory.createRoot(), "fieldName2", FieldIndexOrdering.ASC);
    MutableMetaSnapshot changedSnapshot = new WrapperMutableMetaSnapshot(currentSnapshot);
    changedSnapshot.getMetaDatabaseByName("dbName1").getMetaCollectionByName("colName1").addMetaIndex("idxName2", false).addMetaIndexField(tableRefFactory.createRoot(), "fieldName2", FieldIndexOrdering.ASC);
    try {
        new SnapshotMerger(currentModifiedSnapshot.immutableCopy(), changedSnapshot).merge();
        Assert.fail("A " + UnmergeableException.class.getSimpleName() + " was expected to be thrown");
    } catch (UnmergeableException ex) {
    }
}
Also used : WrapperMutableMetaSnapshot(com.torodb.core.transaction.metainf.WrapperMutableMetaSnapshot) MutableMetaSnapshot(com.torodb.core.transaction.metainf.MutableMetaSnapshot) UnmergeableException(com.torodb.core.transaction.metainf.UnmergeableException) WrapperMutableMetaSnapshot(com.torodb.core.transaction.metainf.WrapperMutableMetaSnapshot) Test(org.junit.Test)

Aggregations

MutableMetaSnapshot (com.torodb.core.transaction.metainf.MutableMetaSnapshot)74 Test (org.junit.Test)70 WrapperMutableMetaSnapshot (com.torodb.core.transaction.metainf.WrapperMutableMetaSnapshot)69 ImmutableMetaSnapshot (com.torodb.core.transaction.metainf.ImmutableMetaSnapshot)56 UnmergeableException (com.torodb.core.transaction.metainf.UnmergeableException)34 MutableMetaDatabase (com.torodb.core.transaction.metainf.MutableMetaDatabase)3 MergerStage (com.torodb.core.transaction.metainf.MetainfoRepository.MergerStage)2 SnapshotStage (com.torodb.core.transaction.metainf.MetainfoRepository.SnapshotStage)2 Nonnull (javax.annotation.Nonnull)2 SnapshotUpdater (com.torodb.core.backend.SnapshotUpdater)1 DatabaseNotFoundException (com.torodb.core.exceptions.user.DatabaseNotFoundException)1 MutableMetaDocPart (com.torodb.core.transaction.metainf.MutableMetaDocPart)1 Connection (java.sql.Connection)1 SQLException (java.sql.SQLException)1 DSLContext (org.jooq.DSLContext)1