/* This file is part of VoltDB.
* Copyright (C) 2008-2010 VoltDB L.L.C.
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*/
package org.voltdb.catalog;
import junit.framework.TestCase;
import org.voltdb.VoltProcedure;
import org.voltdb.benchmark.tpcc.TPCCProjectBuilder;
import org.voltdb.utils.CatalogUtil;
public class TestCatalogDiffs extends TestCase {
@SuppressWarnings("unchecked")
static final Class<? extends VoltProcedure> BASEPROCS[] = (Class<? extends VoltProcedure>[])new Class<?>[]
{ org.voltdb.benchmark.tpcc.procedures.InsertNewOrder.class,
org.voltdb.benchmark.tpcc.procedures.delivery.class };
@SuppressWarnings("unchecked")
static final Class<? extends VoltProcedure> EXPANDEDPROCS[] = (Class<? extends VoltProcedure>[])new Class<?>[]
{ org.voltdb.benchmark.tpcc.procedures.InsertNewOrder.class,
org.voltdb.benchmark.tpcc.procedures.delivery.class,
org.voltdb.benchmark.tpcc.procedures.slev.class };
@SuppressWarnings("unchecked")
static final Class<? extends VoltProcedure> FEWERPROCS[] = (Class<? extends VoltProcedure>[])new Class<?>[]
{ org.voltdb.benchmark.tpcc.procedures.InsertNewOrder.class };
@SuppressWarnings("unchecked")
static final Class<? extends VoltProcedure> CONFLICTPROCS[] = (Class<? extends VoltProcedure>[])new Class<?>[]
{ org.voltdb.catalog.InsertNewOrder.class,
org.voltdb.benchmark.tpcc.procedures.delivery.class };
protected String compile(String name, Class<? extends VoltProcedure>... procList) {
TPCCProjectBuilder builder = new TPCCProjectBuilder();
builder.addDefaultSchema();
builder.addDefaultPartitioning();
builder.addProcedures(procList);
String retval = "tpcc-catalogcheck-" + name + ".jar";
builder.compile(retval);
return retval;
}
protected Catalog catalogForJar(String pathToJar) {
String serializedCatalog = CatalogUtil.loadCatalogFromJar(pathToJar, null);
assertNotNull(serializedCatalog);
Catalog c = new Catalog();
c.execute(serializedCatalog);
return c;
}
public void testAddProcedure() {
String original = compile("base", BASEPROCS);
Catalog catOriginal = catalogForJar(original);
String updated = compile("expanded", EXPANDEDPROCS);
Catalog catUpdated = catalogForJar(updated);
String updatedSerialized = catUpdated.serialize();
// String diffCommands = CatalogDiffEngine.getCommandsToDiff(catOriginal, catUpdated);
// catOriginal.execute(diffCommands);
// String updatedOriginalSerialized = catOriginal.serialize();
// assertEquals(updatedOriginalSerialized, updatedSerialized);
}
public void testModifyProcedureCode() {
String original = compile("base", BASEPROCS);
Catalog catOriginal = catalogForJar(original);
String updated = compile("conflict", CONFLICTPROCS);
Catalog catUpdated = catalogForJar(updated);
String updatedSerialized = catUpdated.serialize();
// String diffCommands = CatalogDiffEngine.getCommandsToDiff(catOriginal, catUpdated);
// catOriginal.execute(diffCommands);
// String updatedOriginalSerialized = catOriginal.serialize();
// assertEquals(updatedOriginalSerialized, updatedSerialized);
}
public void testDeleteProcedure() {
String original = compile("base", BASEPROCS);
Catalog catOriginal = catalogForJar(original);
String updated = compile("fewer", FEWERPROCS);
Catalog catUpdated = catalogForJar(updated);
String updatedSerialized = catUpdated.serialize();
// String diffCommands = CatalogDiffEngine.getCommandsToDiff(catOriginal, catUpdated);
// catOriginal.execute(diffCommands);
// String updatedOriginalSerialized = catOriginal.serialize();
// assertEquals(updatedOriginalSerialized, updatedSerialized);
}
public void testIsUpIgnored()
{
String original = compile("base", BASEPROCS);
Catalog catOriginal = catalogForJar(original);
catOriginal.getClusters().get("cluster").getSites().add("999");
catOriginal.getClusters().get("cluster").getSites().get("999").set("isUp", "true");
Catalog cat_copy = catOriginal.deepCopy();
// String null_diff = CatalogDiffEngine.getCommandsToDiff(catOriginal, cat_copy);
// assertEquals("", null_diff);
// cat_copy.getClusters().get("cluster").getSites().get("999").set("isUp", "false");
// null_diff = CatalogDiffEngine.getCommandsToDiff(catOriginal, cat_copy);
// assertEquals("", null_diff);
}
}