You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@subversion.apache.org by Yoshiki Hayashi <yo...@xemacs.org> on 2001/02/28 10:29:38 UTC

[PATCH] Test case for svn_fs_abort_txn

(check_node_id): New helper function for abort_transaction.
(abort_transaction): New function to test svn_fs_abort_txn().

Index: fs-test.c
===================================================================
RCS file: /cvs/subversion/subversion/tests/libsvn_fs/fs-test.c,v
retrieving revision 1.14
diff -u -r1.14 fs-test.c
--- fs-test.c	2001/02/28 02:19:55	1.14
+++ fs-test.c	2001/02/28 10:08:43
@@ -18,6 +18,7 @@
 #include "../../libsvn_fs/fs.h"
 #include "../../libsvn_fs/rev-table.h"
 #include "../../libsvn_fs/trail.c"
+#include "../../libsvn_fs/node-rev.h"
 
 /* Some utility functions.  */
 
@@ -341,6 +342,78 @@
 }
 
 
+static svn_error_t *
+check_node_id (void *baton, trail_t *trail)
+{
+  svn_fs_t *fs = baton;
+  skel_t *skel;
+
+  SVN_ERR (svn_fs__get_node_revision (&skel, fs,
+                                      svn_fs_parse_id ("1.1", 3, trail->pool),
+                                      trail));
+
+  return SVN_NO_ERROR;
+}
+
+
+static int
+abort_transaction (const char **msg)
+{
+  svn_fs_t *fs;
+  svn_fs_txn_t *txn;
+  svn_error_t *err;
+  const char *ignored;
+  char *first_txn_id, *second_txn_id;
+  *msg = "begin a transaction, then abort transaction";
+
+  /* Make sure the FS exists. */
+  if (create_berkeley_filesystem (&ignored) != 0)
+    return fail();
+      
+  /* Open the FS. */
+  fs = svn_fs_new (pool);
+  if (fs == NULL)
+    return fail();
+      
+  if (SVN_NO_ERROR != svn_fs_open_berkeley (fs, repository))
+    return fail();
+      
+  /* Make sure the transaction exists. */
+  if (trivial_transaction (&ignored) != 0)
+    return fail();
+  /* Open the transaction, just to make sure it's in the database. */
+  if (SVN_NO_ERROR != svn_fs_open_txn (&txn, fs, "0", pool))
+    return fail();
+
+  if (SVN_NO_ERROR != svn_fs_txn_name (&first_txn_id, txn, pool))
+    return fail();
+  if (SVN_NO_ERROR != svn_fs_abort_txn (txn))
+    return fail();
+
+  err = svn_fs_open_txn (&txn, fs, first_txn_id, pool);
+  if (!err || err->apr_err != SVN_ERR_FS_NO_SUCH_TRANSACTION)
+    return fail();
+
+  /* Previously created node revision of "beer.txt" must be gone now.
+     ### Create more complex structure.  */
+  err = svn_fs__retry_txn (fs, check_node_id, fs, fs->pool);
+  if (!err || err->apr_err != SVN_ERR_FS_CORRUPT)
+    return fail();
+
+  /* Begin new transaction.  */
+  if (SVN_NO_ERROR != svn_fs_begin_txn (&txn, fs, 0, pool))
+    fail();
+
+  if (SVN_NO_ERROR != svn_fs_txn_name (&second_txn_id, txn, pool))
+      return fail();
+
+  /* Transaction id must be different.  */
+  if (! strcmp (first_txn_id, second_txn_id))
+    fail();
+
+  return 0;
+}
+
 
 /* The test table.  */
 
@@ -352,6 +425,7 @@
   reopen_trivial_transaction,
   create_file_transaction,
   list_live_transactions,
+  abort_transaction,
   0
 };
 


-- 
Yoshiki Hayashi

[PATCH] test case for svn_fs_revision_prop

Posted by Yoshiki Hayashi <yo...@xemacs.org>.
Yoshiki Hayashi <yo...@xemacs.org> writes:

> Updated to follow yesterday's changes.
> 
> (abort_transaction): New function to test svn_fs_abort_txn().

Sorry for sending patches for the same file again.  This one
includes test case for svn_fs_revision_prop.

(abort_transaction): New function to test svn_fs_abort_txn.
(revision_property): New function to test
  svn_fs_revision_prop, svn_fs_revision_proplist,
  svn_fs_change_rev_prop.

Index: fs-test.c
===================================================================
RCS file: /cvs/subversion/subversion/tests/libsvn_fs/fs-test.c,v
retrieving revision 1.18
diff -u -r1.18 fs-test.c
--- fs-test.c	2001/03/01 00:06:10	1.18
+++ fs-test.c	2001/03/01 07:56:35
@@ -322,7 +322,134 @@
 #endif /* 0 */
 
 
+static svn_error_t *
+abort_transaction (const char **msg)
+{
+  svn_fs_t *fs;
+  svn_fs_txn_t *txn;
+  svn_fs_root_t *txn_root;
+  svn_error_t *err;
+  char *first_txn_id, *second_txn_id;
+  svn_fs_id_t *first_id, *second_id;
+  *msg = "begin a transaction, then abort transaction";
 
+  SVN_ERR (create_fs_and_repos (&fs, "test-repo-8")); /* helper */
+  SVN_ERR (svn_fs_begin_txn (&txn, fs, 0, pool));
+  SVN_ERR (svn_fs_txn_root (&txn_root, txn, pool));
+  SVN_ERR (svn_fs_txn_name (&first_txn_id, txn, pool));
+
+  /* Create a new file in the root directory.
+     ### Use more complex structure.  */
+  SVN_ERR (svn_fs_make_file (txn_root, "my_file.txt", pool));
+  SVN_ERR (svn_fs_node_id (&first_id, txn_root, "/my_file.txt", pool));
+  SVN_ERR (svn_fs_abort_txn (txn));
+
+  err = svn_fs_open_txn (&txn, fs, first_txn_id, pool);
+  if (!err || err->apr_err != SVN_ERR_FS_NO_SUCH_TRANSACTION)
+    return svn_error_create (SVN_ERR_FS_GENERAL, 0, NULL, pool,
+                             "Failed to abort transaction");
+
+  /* Begin a new transaction.  */
+  SVN_ERR (svn_fs_begin_txn (&txn, fs, 0, pool));
+  SVN_ERR (svn_fs_txn_root (&txn_root, txn, pool));
+  SVN_ERR (svn_fs_txn_name (&second_txn_id, txn, pool));
+
+  /* Transaction id must be different.  */
+  if (! strcmp (first_txn_id, second_txn_id))
+    svn_error_create (SVN_ERR_FS_GENERAL, 0, NULL, pool,
+                      "Different transaction must have different ID.");
+
+  /* Previously created node revision of "beer.txt" must be gone now.  */
+  {
+    /* Create "beer.txt" again.  Since there were no other
+       transactions, it must have the same revision node ID.  */
+    SVN_ERR (svn_fs_make_file (txn_root, "beer.txt", pool));
+    SVN_ERR (svn_fs_node_id (&second_id, txn_root, "/beer.txt", pool));
+    if (! svn_fs_id_eq (first_id, second_id))
+      svn_error_create (SVN_ERR_FS_GENERAL, 0, NULL, pool,
+                        "Failed to remove mutable file");
+  }
+
+  return SVN_NO_ERROR;
+}
+
+
+/* Put revision properties, fetch them and remove them.  */
+static svn_error_t *
+revision_property (char const **msg)
+{
+  svn_fs_t *fs;
+  apr_hash_t *prop_table;
+  svn_string_t *prop1, *value1, *prop2, *value2, *prop3, *value3;
+  svn_string_t *prop4, *value4;
+  svn_string_t *value, *newval;
+  *msg = "Put revision properties, fetch them and remove them";
+
+  SVN_ERR (create_fs_and_repos (&fs, "test-repo-9")); /* helper */
+
+  prop1 = svn_string_create ("prop1", pool);
+  value1 = svn_string_create ("value1", pool);
+  prop2 = svn_string_create ("prop2", pool);
+  value2 = svn_string_create ("value2", pool);
+  prop3 = svn_string_create ("prop3", pool);
+  value3 = svn_string_create ("value3", pool);
+  prop4 = svn_string_create ("prop4", pool);
+  value4 = svn_string_create ("value4", pool);
+  newval = svn_string_create ("newval", pool);
+
+  /* Put new properties.  */
+  SVN_ERR (svn_fs_change_rev_prop (fs, 0, prop1, value1, pool));
+  SVN_ERR (svn_fs_change_rev_prop (fs, 0, prop2, value2, pool));
+  SVN_ERR (svn_fs_change_rev_prop (fs, 0, prop3, value3, pool));
+  SVN_ERR (svn_fs_change_rev_prop (fs, 0, prop4, value4, pool));
+
+  /* Get property.  */
+  SVN_ERR (svn_fs_revision_prop (&value, fs, 0, prop1, pool));
+  if (! svn_string_compare (value1, value))
+    return svn_error_create (SVN_ERR_FS_GENERAL, 0, NULL, pool,
+                             "Get different revision property");
+  /* Update it.  */
+  SVN_ERR (svn_fs_change_rev_prop (fs, 0, prop1, newval, pool));
+  SVN_ERR (svn_fs_revision_prop (&value, fs, 0, prop1, pool));
+  if (! svn_string_compare (newval, value))
+    return svn_error_create (SVN_ERR_FS_GENERAL, 0, NULL, pool,
+                             "Failed to update revision property");
+  
+  /* Test proplist.  */
+  SVN_ERR (svn_fs_revision_proplist (&prop_table, fs, 0, pool));
+  if (apr_hash_count (prop_table) != 4)
+    return svn_error_create (SVN_ERR_FS_GENERAL, 0, NULL, pool,
+                             "Wrong number of properties");
+
+  /* Remove.  */
+  SVN_ERR (svn_fs_change_rev_prop (fs, 0, prop3, 0, pool));
+  SVN_ERR (svn_fs_revision_proplist (&prop_table, fs, 0, pool));
+  if (apr_hash_count (prop_table) != 3)
+    return svn_error_create (SVN_ERR_FS_GENERAL, 0, NULL, pool,
+                             "Wrong number of properties");
+
+  SVN_ERR (svn_fs_change_rev_prop (fs, 0, prop2, 0, pool));
+  SVN_ERR (svn_fs_revision_proplist (&prop_table, fs, 0, pool));
+  if (apr_hash_count (prop_table) != 2)
+    return svn_error_create (SVN_ERR_FS_GENERAL, 0, NULL, pool,
+                             "Wrong number of properties");
+
+  SVN_ERR (svn_fs_change_rev_prop (fs, 0, prop1, 0, pool));
+  SVN_ERR (svn_fs_revision_proplist (&prop_table, fs, 0, pool));
+  if (apr_hash_count (prop_table) != 1)
+    return svn_error_create (SVN_ERR_FS_GENERAL, 0, NULL, pool,
+                             "Wrong number of properties");
+
+  SVN_ERR (svn_fs_change_rev_prop (fs, 0, prop4, 0, pool));
+  SVN_ERR (svn_fs_revision_proplist (&prop_table, fs, 0, pool));
+  if (apr_hash_count (prop_table) != 0)
+    return svn_error_create (SVN_ERR_FS_GENERAL, 0, NULL, pool,
+                             "Wrong number of properties");
+
+  return SVN_NO_ERROR;
+}
+
+
 
 /* The test table.  */
 
@@ -335,6 +462,8 @@
   reopen_trivial_transaction,
   create_file_transaction,
   verify_txn_list,
+  abort_transaction,
+  revision_property,
   0
 };
 


-- 
Yoshiki Hayashi

Re: [PATCH] Test case for svn_fs_abort_txn

Posted by Yoshiki Hayashi <yo...@xemacs.org>.
Yoshiki Hayashi <yo...@xemacs.org> writes:

> (check_node_id): New helper function for abort_transaction.
> (abort_transaction): New function to test svn_fs_abort_txn().

Updated to follow yesterday's changes.

(abort_transaction): New function to test svn_fs_abort_txn().

Index: fs-test.c
===================================================================
RCS file: /cvs/subversion/subversion/tests/libsvn_fs/fs-test.c,v
retrieving revision 1.18
diff -u -r1.18 fs-test.c
--- fs-test.c	2001/03/01 00:06:10	1.18
+++ fs-test.c	2001/03/01 07:03:50
@@ -322,7 +322,58 @@
 #endif /* 0 */
 
 
+static svn_error_t *
+abort_transaction (const char **msg)
+{
+  svn_fs_t *fs;
+  svn_fs_txn_t *txn;
+  svn_fs_root_t *txn_root;
+  svn_error_t *err;
+  char *first_txn_id, *second_txn_id;
+  svn_fs_id_t *first_id, *second_id;
+  *msg = "begin a transaction, then abort transaction";
 
+  SVN_ERR (create_fs_and_repos (&fs, "test-repo-8")); /* helper */
+  SVN_ERR (svn_fs_begin_txn (&txn, fs, 0, pool));
+  SVN_ERR (svn_fs_txn_root (&txn_root, txn, pool));
+  SVN_ERR (svn_fs_txn_name (&first_txn_id, txn, pool));
+
+  /* Create a new file in the root directory.
+     ### Use more complex structure.  */
+  SVN_ERR (svn_fs_make_file (txn_root, "my_file.txt", pool));
+  SVN_ERR (svn_fs_node_id (&first_id, txn_root, "/my_file.txt", pool));
+  SVN_ERR (svn_fs_abort_txn (txn));
+
+  err = svn_fs_open_txn (&txn, fs, first_txn_id, pool);
+  if (!err || err->apr_err != SVN_ERR_FS_NO_SUCH_TRANSACTION)
+    return svn_error_create (SVN_ERR_FS_GENERAL, 0, NULL, pool,
+                             "Failed to abort transaction");
+
+  /* Begin a new transaction.  */
+  SVN_ERR (svn_fs_begin_txn (&txn, fs, 0, pool));
+  SVN_ERR (svn_fs_txn_root (&txn_root, txn, pool));
+  SVN_ERR (svn_fs_txn_name (&second_txn_id, txn, pool));
+
+  /* Transaction id must be different.  */
+  if (! strcmp (first_txn_id, second_txn_id))
+    svn_error_create (SVN_ERR_FS_GENERAL, 0, NULL, pool,
+                      "Different transaction must have different ID.");
+
+  /* Previously created node revision of "beer.txt" must be gone now.  */
+  {
+    /* Create "beer.txt" again.  Since there were no other
+       transactions, it must have the same revision node ID.  */
+    SVN_ERR (svn_fs_make_file (txn_root, "beer.txt", pool));
+    SVN_ERR (svn_fs_node_id (&second_id, txn_root, "/beer.txt", pool));
+    if (! svn_fs_id_eq (first_id, second_id))
+      svn_error_create (SVN_ERR_FS_GENERAL, 0, NULL, pool,
+                        "Failed to remove mutable file");
+  }
+
+  return SVN_NO_ERROR;
+}
+
+
 
 /* The test table.  */
 
@@ -335,6 +386,7 @@
   reopen_trivial_transaction,
   create_file_transaction,
   verify_txn_list,
+  abort_transaction,
   0
 };
 


-- 
Yoshiki Hayashi