gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[GNUnet-SVN] [taler-twister] 01/02: adding flip command, boilerplate (in


From: gnunet
Subject: [GNUnet-SVN] [taler-twister] 01/02: adding flip command, boilerplate (including failing test)
Date: Thu, 22 Mar 2018 16:42:03 +0100

This is an automated email from the git hooks/post-receive script.

marcello pushed a commit to branch master
in repository twister.

commit 600c003c034fac5b15866a24ab5274192ede8840
Author: Marcello Stanisci <address@hidden>
AuthorDate: Thu Mar 22 14:52:10 2018 +0100

    adding flip command, boilerplate (including failing test)
---
 src/include/taler_twister_service.h | 19 ++++++++++++++++++
 src/test/test_twister.sh            | 15 +++++++++++++-
 src/twister/taler-twister-service.c | 28 +++++++++++++++++++++++++-
 src/twister/taler-twister.c         | 21 +++++++++++++++++++
 src/twister/twister.h               | 28 ++++++++++++++++++++++++++
 src/twister/twister_api.c           | 40 +++++++++++++++++++++++++++++++++++++
 6 files changed, 149 insertions(+), 2 deletions(-)

diff --git a/src/include/taler_twister_service.h 
b/src/include/taler_twister_service.h
index 486baf2..7adf40e 100644
--- a/src/include/taler_twister_service.h
+++ b/src/include/taler_twister_service.h
@@ -96,6 +96,25 @@ TALER_TWISTER_modify_path (struct TALER_TWISTER_Handle *h,
                            void *cb_cls);
 
 /**
+ * Randomly flip a character into the JSON string
+ * object pointed to by @a path.
+ *
+ * @param h twister instance to control
+ * @param path object-like notation to point the string
+ *        object where we seek a character to flip.
+ * @param cb function to call once twister is ready
+ * @param cb_cls closure for @a cb
+ * @return operation handle (to possibly abort)
+ */
+struct TALER_TWISTER_Operation *
+TALER_TWISTER_flip_path
+  (struct TALER_TWISTER_Handle *h,
+   const char *path,
+   GNUNET_SCHEDULER_TaskCallback cb,
+   void *cb_cls);
+
+
+/**
  * Change the next response code to @a new_rc.
  *
  * @param h twister instance to control
diff --git a/src/test/test_twister.sh b/src/test/test_twister.sh
index 1413a0d..60c7a36 100755
--- a/src/test/test_twister.sh
+++ b/src/test/test_twister.sh
@@ -39,11 +39,24 @@ if test '{"hello":[{"this":"browser!"}],"when":"today"}' = \
 fi
 
 
+# flip string.
+taler-twister -c ./test_twister.conf -f "when"
+flip_body=$(curl -s ${TWISTER_URL})
+flip_field=$(echo $flip_body | tr -d '"}{' | awk -F, '{print $2}' | awk -F: 
'{print $2}')
+
+# check if pointed object was flipped.
+if test "$flip_field" = 'today'; then
+  printf "Response body (%s) has not been flipped as expected\n" "$flip_body"
+  kill $web_server_pid
+  kill $twister_service_pid
+  exit 1
+fi
+
 # delete object.
 taler-twister -c ./test_twister.conf -d "hello.0"
 emptied_body=$(curl -s ${TWISTER_URL})
 
-# check response body has been emptied
+# check if pointed object was deleted.
 if ! test '{"hello":[],"when":"today"}' = "$emptied_body"; then
   printf "Response body (%s) has not been emptied as expected\n" \
     "$emptied_body"
diff --git a/src/twister/taler-twister-service.c 
b/src/twister/taler-twister-service.c
index 8eda2a6..bed6f2a 100644
--- a/src/twister/taler-twister-service.c
+++ b/src/twister/taler-twister-service.c
@@ -253,6 +253,12 @@ static unsigned int hack_response_code;
 static char delete_path[TWISTER_PATH_LENGTH] = {'\0'};
 
 /**
+ * Will point to a JSON string object which will get a
+ * character flipped.
+ */
+static char flip_path[TWISTER_PATH_LENGTH] = {'\0'};
+
+/**
  * Will point to a JSON object to modify 
  */
 static char modify_path[TWISTER_PATH_LENGTH] = {'\0'};
@@ -1872,6 +1878,21 @@ handle_modify_path (void *cls,
   send_acknowledgement (c);
 }
 
+/**
+ * Control handler for deleting JSON objects
+ *
+ * @param cls message queue for sending replies
+ * @param src received message
+ */
+static void
+handle_flip_path (void *cls,
+                  const struct TWISTER_FlipPath *src)
+{
+  struct GNUNET_SERVICE_Client *c = cls;
+
+  strcpy (flip_path, src->path);
+  send_acknowledgement (c);
+}
 
 /**
  * Control handler for deleting JSON objects
@@ -1889,7 +1910,6 @@ handle_delete_path (void *cls,
   send_acknowledgement (c);
 }
 
-
 /**
  * Control handler for changing the response code
  *
@@ -1942,6 +1962,12 @@ GNUNET_SERVICE_MAIN
                          struct TWISTER_DeletePath,
                          NULL),
 
+ GNUNET_MQ_hd_fixed_size (flip_path,
+                         TWISTER_MESSAGE_TYPE_FLIP_PATH,
+                         struct TWISTER_FlipPath,
+                         NULL),
+
+
  GNUNET_MQ_handler_end ());
 
 
diff --git a/src/twister/taler-twister.c b/src/twister/taler-twister.c
index ce39104..3ff4a04 100644
--- a/src/twister/taler-twister.c
+++ b/src/twister/taler-twister.c
@@ -63,6 +63,11 @@ static int malform_response;
 static int malform_upload;
 
 /**
+ * Path to the string json object to flip.
+ */
+static char *flip_path;
+
+/**
  * Path to the object to modify.
  */
 static char *modify_path;
@@ -175,6 +180,14 @@ run (void *cls,
 
   /* TODO: add other operations here */
 
+  if ( (NULL != flip_path) &&
+       (NULL != TALER_TWISTER_flip_path
+         (tth,
+          flip_path,
+          &handle_acknowledgement,
+          NULL)) )
+    num_ops++;
+
   if ( (NULL != delete_path) &&
        (NULL != TALER_TWISTER_delete_path
          (tth,
@@ -230,6 +243,14 @@ main (int argc,
        &modify_path),
 
     GNUNET_GETOPT_option_string
+      ('f',
+       "flip",
+       "PATH",
+       gettext_noop
+         ("Flip a char in the _string_ object pointed by PATH.\n"),
+       &flip_path),
+
+    GNUNET_GETOPT_option_string
       ('V',
        "value",
        "VALUE",
diff --git a/src/twister/twister.h b/src/twister/twister.h
index c1ebeef..3e943f7 100644
--- a/src/twister/twister.h
+++ b/src/twister/twister.h
@@ -51,6 +51,8 @@
 
 #define TWISTER_MESSAGE_TYPE_MALFORM_UPLOAD 6
 
+#define TWISTER_MESSAGE_TYPE_FLIP_PATH 7
+
 GNUNET_NETWORK_STRUCT_BEGIN
 struct TWISTER_Malform
 {
@@ -92,6 +94,32 @@ GNUNET_NETWORK_STRUCT_BEGIN
  * standard deviation of known estimates.
  *
  */
+struct TWISTER_FlipPath
+{
+  /**
+   * Type: #TWISTER_MESSAGE_TYPE_DELETE_PATH
+   */
+  struct GNUNET_MessageHeader header;
+
+  /**
+   * The new response code, in big endian.
+   */
+  char path[TWISTER_PATH_LENGTH];
+};
+
+GNUNET_NETWORK_STRUCT_END
+
+
+
+GNUNET_NETWORK_STRUCT_BEGIN
+
+/**
+ * Network size estimate sent from the service
+ * to clients.  Contains the current size estimate
+ * (or 0 if none has been calculated) and the
+ * standard deviation of known estimates.
+ *
+ */
 struct TWISTER_DeletePath
 {
   /**
diff --git a/src/twister/twister_api.c b/src/twister/twister_api.c
index 477b774..aa96e6f 100644
--- a/src/twister/twister_api.c
+++ b/src/twister/twister_api.c
@@ -276,6 +276,46 @@ TALER_TWISTER_malform
 
 
 /**
+ * Randomly flip a character into the JSON string
+ * object pointed to by @a path.
+ *
+ * @param h twister instance to control
+ * @param path object-like notation to point the string
+ *        object where we seek a character to flip.
+ * @param cb function to call once twister is ready
+ * @param cb_cls closure for @a cb
+ * @return operation handle (to possibly abort)
+ */
+struct TALER_TWISTER_Operation *
+TALER_TWISTER_flip_path
+  (struct TALER_TWISTER_Handle *h,
+   const char *path,
+   GNUNET_SCHEDULER_TaskCallback cb,
+   void *cb_cls)
+{
+  struct TALER_TWISTER_Operation *op;
+  struct GNUNET_MQ_Envelope *env;
+  struct TWISTER_FlipPath *src; //FIXME 'src' right name?
+
+  op = GNUNET_new (struct TALER_TWISTER_Operation);
+  op->h = h;
+  op->cb = cb;
+  op->cb_cls = cb_cls;
+  GNUNET_CONTAINER_DLL_insert_tail (h->op_head,
+                                    h->op_tail,
+                                    op);
+  /* Prepare *env*elope. */
+  env = GNUNET_MQ_msg
+    (src, TWISTER_MESSAGE_TYPE_FLIP_PATH);
+  /* Put data into the envelope. */
+  strcpy (src->path, path);
+  /* Send message. */
+  GNUNET_MQ_send (h->mq, env);
+  return op;
+}
+
+
+/**
  * Delete the object pointed to by @a path.
  *
  * @param h twister instance to control

-- 
To stop receiving notification emails like this one, please contact
address@hidden



reply via email to

[Prev in Thread] Current Thread [Next in Thread]