gt:         CatalogContext cc = this.getCatalogContext();       
context: /* This file is part of VoltDB.
   * Copyright (C) 2008-2010 VoltDB Inc.
   *
   * 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.regressionsuites;
  
  import java.io.ByteArrayOutputStream;
  import java.io.File;
  import java.io.FilenameFilter;
  import java.io.IOException;
  import java.io.PrintStream;
  import java.io.UnsupportedEncodingException;
  import java.util.Arrays;
  import java.util.Calendar;
  import java.util.Iterator;
  
  import junit.framework.Test;
  
  import org.voltdb.BackendTarget;
  import org.voltdb.CatalogContext;
  import org.voltdb.DefaultSnapshotDataTarget;
  import org.voltdb.VoltTable;
  import org.voltdb.benchmark.tpcc.TPCCClient;
  import org.voltdb.benchmark.tpcc.TPCCLoader;
  import org.voltdb.benchmark.tpcc.TPCCProjectBuilder;
  import org.voltdb.catalog.CatalogMap;
  import org.voltdb.catalog.Procedure;
  import org.voltdb.catalog.Site;
  import org.voltdb.client.Client;
  import org.voltdb.client.ClientResponse;
  import org.voltdb.client.NoConnectionsException;
  import org.voltdb.client.ProcCallException;
  import org.voltdb.utils.SnapshotVerifier;
  
  import edu.brown.hstore.HStoreConstants;
  import edu.brown.hstore.Hstoreservice.Status;
  import edu.brown.hstore.cmdlog.CommandLogReader;
  import edu.brown.hstore.cmdlog.CommandLogWriter;
  import edu.brown.hstore.cmdlog.LogEntry;
  
  /**
   * Test logical recovery
   */
  public class TestTPCCLogicalRecovery extends RegressionSuite {
  
      private static final String TMPDIR = "./obj/snapshot";
      private static final String CMDLOGDIR = "./obj/cmdlog";
  
      private static final String TESTNONCE = "testnonce";
      private static final int ALLOWEXPORT = 0;
  
      private static int NUM_SITES = -1;
      private static int NUM_PARTITIONS = -1;
  
      // TPCC
      private static final String PREFIX = "tpcc";
      private static int NUM_TRANSACTIONS = 500;
      private static final String projectJAR = "logical_" + PREFIX + ".jar";
  
      public TestTPCCLogicalRecovery(String name) {
          super(name);
      }
  
      @Override
      public void setUp() {
          deleteTestFiles();
          deleteCommandLogDir();
          super.setUp();
          DefaultSnapshotDataTarget.m_simulateFullDiskWritingChunk = false;
          DefaultSnapshotDataTarget.m_simulateFullDiskWritingHeader = false;
          org.voltdb.sysprocs.SnapshotRegistry.clear();
      }
  
      @Override
      public void tearDown() {
          try {
              deleteTestFiles();
              deleteCommandLogDir();
              super.tearDown();
          } catch (final Exception e) {
              e.printStackTrace();
          }
      }    
  
      private void deleteTestFiles() {
          FilenameFilter cleaner = new FilenameFilter() {
              public boolean accept(File dir, String file) {
                  return file.startsWith(TESTNONCE) || file.endsWith(".vpt") || file.endsWith(".digest") || file.endsWith(".tsv") || file.endsWith(".csv");
              }
          };
  
          File tmp_dir = new File(TMPDIR);
          File[] tmp_files = tmp_dir.listFiles(cleaner);
          for (File tmp_file : tmp_files) {
              tmp_file.delete();
          }
  
      }
  
      private static synchronized void deleteCommandLogDir() {
          try {
              File cmdlogDir = new File(CMDLOGDIR);
  
              if (cmdlogDir.exists()) {
                  File[] log_files = cmdlogDir.listFiles();
                  for (File log_file : log_files) {
                      log_file.delete();
                  }
              }
          } catch (Exception e) {
              e.printStackTrace();
          }
      }
  
      private static synchronized void setUpSnapshotDir() {
          try {
              File snapshotDir = new File(TMPDIR);
  
              if (!snapshotDir.exists()) {
                  boolean result = snapshotDir.mkdir();
                  if (result) {
                      System.out.println("Created snapshot directory.");
                  }
              }
          } catch (Exception e) {
              e.printStackTrace();
          }
      }
  
      private VoltTable[] saveTables(Client client) {
          VoltTable[] results = null;
          try {
              results = client.callProcedure("@SnapshotSave", TMPDIR, TESTNONCE, (byte) 1).getResults();
          } catch (Exception ex) {
              ex.printStackTrace();
              fail("SnapshotSave exception: " + ex.getMessage());
          }
          return results;
      }
  
      private void validateSnapshot(boolean expectSuccess) {
          ByteArrayOutputStream baos = new ByteArrayOutputStream();
          PrintStream ps = new PrintStream(baos);
          PrintStream original = System.out;
          try {
              System.setOut(ps);
              String args[] = new String[] { TESTNONCE, "--dir", TMPDIR };
              SnapshotVerifier.main(args);
              ps.flush();
              String reportString = baos.toString("UTF-8");
  
              // System.err.println("Validate Snapshot :"+reportString);
  
              if (expectSuccess) {
                  assertTrue(reportString.startsWith("Snapshot valid\n"));
                  System.err.println("Validate Snapshot :" + "Snapshot valid");
              } else {
                  assertTrue(reportString.startsWith("Snapshot corrupted\n"));
                  System.err.println("Validate Snapshot :" + "Snapshot corrupted");
              }
          } catch (UnsupportedEncodingException e) {
          } finally {
              System.setOut(original);
          }
      }
  
      public void initializeTPCCDatabase(final CatalogContext catalogContext, final Client client, boolean scaleItems) throws Exception {
          String args[] = {
              "NOCONNECTIONS=true",
              "BENCHMARK.WAREHOUSE_PER_PARTITION=true",
              "BENCHMARK.NUM_LOADTHREADS=4",
              "BENCHMARK.SCALE_ITEMS="+scaleItems,
          };
          TPCCLoader loader = new TPCCLoader(args) {
              {
                  this.setCatalogContext(catalogContext);
                  this.setClientHandle(client);
              }
              @Override
              public CatalogContext getCatalogContext() {
                  return (catalogContext);
              }
          };
          loader.load();
      }
      
      
      public void testTPCC() throws IOException, InterruptedException, ProcCallException {
  
          System.out.println("Starting testTPCC - Logical Recovery");                
  
          deleteTestFiles();
          setUpSnapshotDir();
  
          VoltTable results[] = null;
          Client client = this.getClient();
  