Search in sources :

Example 1 with EqualityState

use of com.axway.ats.common.dbaccess.snapshot.equality.EqualityState in project ats-framework by Axway.

the class DatabaseSnapshot method compare.

/**
     * Compare both snapshots
     * Both snapshots will be loaded from the database and compared table by table.
     * But if they were saved in files, they will be loaded from the files and compared table by table
     * 
     * @param that the snapshot to compare to
     * @throws DatabaseSnapshotException
     */
@PublicAtsApi
public void compare(DatabaseSnapshot that) throws DatabaseSnapshotException {
    try {
        if (that == null) {
            throw new DatabaseSnapshotException("Snapshot to compare is null");
        }
        if (this.name.equals(that.name)) {
            throw new DatabaseSnapshotException("You are trying to compare snapshots with same name: " + this.name);
        }
        if (this.metadataTimestamp == -1) {
            throw new DatabaseSnapshotException("You are trying to compare snapshots but [" + this.name + "] snapshot is still not created");
        }
        if (that.metadataTimestamp == -1) {
            throw new DatabaseSnapshotException("You are trying to compare snapshots but [" + that.name + "] snapshot is still not created");
        }
        log.debug("Comparing snapshots [" + this.name + "] taken on " + DatabaseSnapshotUtils.dateToString(this.metadataTimestamp) + " and [" + that.name + "] taken on " + DatabaseSnapshotUtils.dateToString(that.metadataTimestamp));
        this.equality = new EqualityState(this.name, that.name);
        // make copies of the table info, as we will remove from these lists,
        // but we do not want to remove from the original table info lists
        List<TableDescription> thisTables = new ArrayList<TableDescription>(this.tables);
        List<TableDescription> thatTables = new ArrayList<TableDescription>(that.tables);
        // Here we put all skip rules into one list. It doesn't make sense to ask people 
        // to add same skip rules for same tables in both snapshot instances.
        Map<String, SkipRules> allSkipRules = mergeSkipRules(that.skipRulesPerTable);
        Set<String> allTablesContentSkip = mergeTableContentToSkip(that.skipTableContent);
        Map<String, Map<String, String>> allSkipRows = mergeSkipRows(that.skipRows);
        Set<String> allTablesToSkip = getAllTablesToSkip(allSkipRules);
        // We can use just one index name matcher
        IndexNameMatcher actualIndexNameMatcher = mergeIndexNameMatchers(that.indexNameMatcher);
        compareTables(this.name, thisTables, that.name, thatTables, that.dbProvider, allTablesToSkip, allSkipRules, allTablesContentSkip, allSkipRows, actualIndexNameMatcher, that.backupXmlFile, equality);
        if (equality.hasDifferences()) {
            // there are some unexpected differences
            throw new DatabaseSnapshotException(equality);
        } else {
            log.info("Successful verification");
        }
    } finally {
        // close the database connections
        disconnect(this.dbProvider, "after comparing database snapshots");
        if (that != null) {
            disconnect(that.dbProvider, "after comparing database snapshots");
        }
    }
}
Also used : EqualityState(com.axway.ats.common.dbaccess.snapshot.equality.EqualityState) ArrayList(java.util.ArrayList) IndexNameMatcher(com.axway.ats.common.dbaccess.snapshot.IndexNameMatcher) TableDescription(com.axway.ats.common.dbaccess.snapshot.TableDescription) HashMap(java.util.HashMap) Map(java.util.Map) DatabaseSnapshotException(com.axway.ats.common.dbaccess.snapshot.DatabaseSnapshotException) PublicAtsApi(com.axway.ats.common.PublicAtsApi)

Aggregations

PublicAtsApi (com.axway.ats.common.PublicAtsApi)1 DatabaseSnapshotException (com.axway.ats.common.dbaccess.snapshot.DatabaseSnapshotException)1 IndexNameMatcher (com.axway.ats.common.dbaccess.snapshot.IndexNameMatcher)1 TableDescription (com.axway.ats.common.dbaccess.snapshot.TableDescription)1 EqualityState (com.axway.ats.common.dbaccess.snapshot.equality.EqualityState)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1