@Test public void testCurrentVersionStructureAgainstGold() throws Throwable { int latestVersion = CatalogVersions.getCurrentVersion().getSchemaVersion(); String[] lastKnown = UpgradeTestUtils.getGoldVersion(latestVersion); String[] current = generateCatalog(); Pattern thanksHibernate = Pattern.compile("(alter table )(\\w+)( add index )(\\w+)(.*add constraint )(\\w+)(.*)"); assertEquals("number of stmts in schema ddl", lastKnown.length, current.length - 1); for (int i = 0; i < current.length - 1; i++) { if (!lastKnown[i].equals(current[i])) { // accept differences in index, constraint names if (lastKnown[i].startsWith("alter table") && current[i].startsWith("alter table")) { Matcher last = thanksHibernate.matcher(lastKnown[i]); Matcher now = thanksHibernate.matcher(current[i]); if (last.matches() && now.matches()) { String knownConstraint = lastKnown[i].substring(last.start(6), last.end(6)); String knownIndex = lastKnown[i].substring(last.start(4), last.end(4)); StringBuilder buf = new StringBuilder(); buf.append(current[i].substring(0, now.start(4))); buf.append(knownIndex); buf.append(current[i].substring(now.end(4), now.start(6))); buf.append(knownConstraint); buf.append(current[i].substring(now.end(6))); String munged = buf.toString(); if (lastKnown[i].equals(munged)) continue; } } assertEquals("schema ddl stmt " + i, lastKnown[i], current[i]); } } }
@Test public void testCurrentVersionContentsAgainstGold() throws Throwable { int latestVersion = CatalogVersions.getCurrentVersion().getSchemaVersion(); String[] lastKnown = UpgradeTestUtils.getInfoSchema(latestVersion); String[] current = CatalogSchemaGenerator.buildTestCurrentInfoSchema(); assertEquals("number of stmts in info schema dml", lastKnown.length, current.length); for (int i = 0; i < lastKnown.length; i++) { assertEquals("info schema dml " + i, lastKnown[i], current[i]); } }