public GetChecksums ( ) : VxSchemaChecksums | ||
Résultat | VxSchemaChecksums |
public void TestCopySchema() { SchemaCreator sc = new SchemaCreator(this); sc.Create(); string msg2 = "Hello, world, this used to be Func1!"; string func1q2 = "create procedure Func1 as select '" + msg2 + "'\n"; VxSchema origschema = dbus.Get(); VxSchemaChecksums origsums = dbus.GetChecksums(); string tmpdir = GetTempDir(); try { Directory.CreateDirectory(tmpdir); VxDiskSchema disk = new VxDiskSchema(tmpdir); // Test that the copy function will create new elements VxSchema.CopySchema(dbus, disk); VxSchema newschema = disk.Get(null); VxSchemaChecksums newsums = disk.GetChecksums(); WVPASS(1); TestSchemaEquality(origschema, newschema); WVPASS(2); TestChecksumEquality(origsums, newsums); WVPASS(3); // Test that the copy function updates changed elements, and // deletes old ones. origschema["Procedure/Func1"].text = func1q2; dbus.Put(origschema, null, VxPutOpts.None); dbus.DropSchema("Table/Tab2"); origschema.Remove("Table/Tab2"); origsums = dbus.GetChecksums(); VxSchema.CopySchema(dbus, disk); newschema = disk.Get(null); newsums = disk.GetChecksums(); WVPASS(4); TestSchemaEquality(origschema, newschema); WVPASS(5); TestChecksumEquality(origsums, newsums); WVPASS(6); } finally { Directory.Delete(tmpdir, true); } WVPASS(!Directory.Exists(tmpdir)); sc.Cleanup(); }
public void TestExportSchema() { SchemaCreator sc = new SchemaCreator(this); string tmpdir = GetTempDir(); DirectoryInfo tmpdirinfo = new DirectoryInfo(tmpdir); try { tmpdirinfo.Create(); // Establish a baseline for the number of existing elements. VxSchema schema = dbus.Get(); VxSchemaChecksums sums = dbus.GetChecksums(); VxDiskSchema disk = new VxDiskSchema(tmpdir); disk.Put(schema, sums, VxPutOpts.None); var base_filecounts = GetFileCounts(tmpdir); // Clobber the directory and start fresh. tmpdirinfo.Delete(true); tmpdirinfo.Create(); // Now create our test schema and do the real tests. sc.Create(); // Check that having mangled checksums fails schema = dbus.Get(); sums = new VxSchemaChecksums(); disk = new VxDiskSchema(tmpdir); try { WVEXCEPT(disk.Put(schema, sums, VxPutOpts.None)); } catch (Wv.Test.WvAssertionFailure e) { throw e; } catch (System.Exception e) { WVPASS(e is ArgumentException); WVPASS(e.Message.StartsWith("Missing checksum for ")); log.print(e.ToString() + "\n"); } // Check that the normal exporting works. schema = dbus.Get(); sums = dbus.GetChecksums(); WVPASSEQ(schema.Count, sums.Count); disk.Put(schema, sums, VxPutOpts.None); int backup_generation = 0; VerifyExportedSchema(tmpdir, schema, sums, sc, backup_generation, base_filecounts); // Check that we read back the same stuff VxSchema schemafromdisk = disk.Get(null); VxSchemaChecksums sumsfromdisk = disk.GetChecksums(); WVPASS(1); TestSchemaEquality(schema, schemafromdisk); TestChecksumEquality(sums, sumsfromdisk); WVPASS(2); // Doing it twice doesn't change anything. disk.Put(schema, sums, VxPutOpts.None); VerifyExportedSchema(tmpdir, schema, sums, sc, backup_generation, base_filecounts); WVPASS(3); // Check backup mode disk.Put(schema, sums, VxPutOpts.IsBackup); backup_generation++; VerifyExportedSchema(tmpdir, schema, sums, sc, backup_generation, base_filecounts); WVPASS(4); // Check backup mode again disk.Put(schema, sums, VxPutOpts.IsBackup); backup_generation++; VerifyExportedSchema(tmpdir, schema, sums, sc, backup_generation, base_filecounts); WVPASS(5); } finally { tmpdirinfo.Delete(true); sc.Cleanup(); } WVASSERT(!tmpdirinfo.Exists); }
public void TestReadChecksums() { SchemaCreator sc = new SchemaCreator(this); sc.Create(); string tmpdir = GetTempDir(); DirectoryInfo tmpdirinfo = new DirectoryInfo(tmpdir); try { tmpdirinfo.Create(); VxSchema schema = dbus.Get(); VxSchemaChecksums sums = dbus.GetChecksums(); VxDiskSchema backend = new VxDiskSchema(tmpdir); backend.Put(schema, sums, VxPutOpts.None); VxSchemaChecksums fromdisk = backend.GetChecksums(); foreach (KeyValuePair<string, VxSchemaChecksum> p in sums) WVPASSEQ(p.Value.GetSumString(), fromdisk[p.Key].GetSumString()); WVPASSEQ(sums.Count, fromdisk.Count); // Test that changing a file invalidates its checksums, and that // we skip directories named "DATA" using (StreamWriter sw = File.AppendText( wv.PathCombine(tmpdir, "Table", "Tab1"))) { sw.WriteLine("Ooga Booga"); } Directory.CreateDirectory(Path.Combine(tmpdir, "DATA")); File.WriteAllText(wv.PathCombine(tmpdir, "DATA", "Decoy"), "Decoy file, shouldn't have checksums"); VxSchemaChecksums mangled = backend.GetChecksums(); // Check that the decoy file didn't get read WVFAIL(mangled.ContainsKey("DATA/Decoy")); // Check that the mangled checksums exist, but are empty. WVASSERT(mangled.ContainsKey("Table/Tab1")); WVASSERT(mangled["Table/Tab1"].GetSumString() != sums["Table/Tab1"].GetSumString()); WVPASSEQ(mangled["Table/Tab1"].GetSumString(), ""); // Check that everything else is still sensible foreach (KeyValuePair<string, VxSchemaChecksum> p in sums) { if (p.Key != "Table/Tab1") WVPASSEQ(p.Value.GetSumString(), mangled[p.Key].GetSumString()); } } finally { tmpdirinfo.Delete(true); sc.Cleanup(); } WVASSERT(!tmpdirinfo.Exists); }
public void TestDropSchemaFromDisk() { string tmpdir = GetTempDir(); try { Directory.CreateDirectory(tmpdir); VxDiskSchema backend = new VxDiskSchema(tmpdir); VxSchema schema = new VxSchema(); schema.Add("Table", "Foo", "column: name=foo,type=int\n", false); schema.Add("Table", "Bar", "column: name=bar,type=int\n", false); schema.Add("Procedure", "Func1", "Func1 contents", false); schema.Add("ScalarFunction", "Func2", "Func2 contents", false); VxSchemaChecksums sums = new VxSchemaChecksums(); sums.AddSum("Table/Foo", 1); sums.AddSum("Table/Bar", 2); sums.AddSum("Procedure/Func1", 3); sums.AddSum("ScalarFunction/Func2", 5); backend.Put(schema, sums, VxPutOpts.None); WVPASS(File.Exists(Path.Combine(tmpdir, "Table/Foo"))); WVPASS(File.Exists(Path.Combine(tmpdir, "Table/Bar"))); WVPASS(File.Exists(Path.Combine(tmpdir, "Procedure/Func1"))); WVPASS(File.Exists(Path.Combine(tmpdir, "ScalarFunction/Func2"))); VxSchema newschema = backend.Get(null); VxSchemaChecksums newsums = backend.GetChecksums(); WVPASSEQ(newschema.Count, schema.Count); WVPASSEQ(newsums.Count, sums.Count); WVPASS(newschema.ContainsKey("Table/Foo")); WVPASS(newschema.ContainsKey("Table/Bar")); WVPASS(newschema.ContainsKey("Procedure/Func1")); WVPASS(newschema.ContainsKey("ScalarFunction/Func2")); string[] todrop = { "Table/Foo" }; backend.DropSchema(todrop); WVPASS(!File.Exists(Path.Combine(tmpdir, "Table/Foo"))) WVPASS(File.Exists(Path.Combine(tmpdir, "Table/Bar"))) WVPASS(File.Exists(Path.Combine(tmpdir, "Procedure/Func1"))) WVPASS(File.Exists(Path.Combine(tmpdir, "ScalarFunction/Func2"))) newschema = backend.Get(null); newsums = backend.GetChecksums(); WVPASSEQ(newschema.Count, 3); WVPASSEQ(newsums.Count, 3); WVPASS(!newschema.ContainsKey("Table/Foo")); WVPASS(newschema.ContainsKey("Table/Bar")); WVPASS(newschema.ContainsKey("Procedure/Func1")); WVPASS(newschema.ContainsKey("ScalarFunction/Func2")); todrop = new string[] { "Procedure/Func1", "ScalarFunction/Func2" }; backend.DropSchema(todrop); WVPASS(!File.Exists(Path.Combine(tmpdir, "Table/Foo"))) WVPASS(File.Exists(Path.Combine(tmpdir, "Table/Bar"))) WVPASS(!File.Exists(Path.Combine(tmpdir, "Procedure/Func1"))) WVPASS(!File.Exists(Path.Combine(tmpdir, "ScalarFunction/Func2"))) newschema = backend.Get(null); newsums = backend.GetChecksums(); WVPASSEQ(newschema.Count, 1); WVPASSEQ(newsums.Count, 1); WVPASS(!newschema.ContainsKey("Table/Foo")); WVPASS(newschema.ContainsKey("Table/Bar")); WVPASS(!newschema.ContainsKey("Procedure/Func1")); WVPASS(!newschema.ContainsKey("ScalarFunction/Func2")); } finally { Directory.Delete(tmpdir, true); } WVPASS(!Directory.Exists(tmpdir)); }