GridLab
Grid Application Toolkit

A simple API for Grid Applications
GAT

Menu



Main Page   Alphabetical List   Compound List   File List   Compound Members   File Members  

gatrequest_tests.c

Go to the documentation of this file.
00001 /** @file gatrequest_tests.c
00002  *
00003  *  Test the GATRequest functionality.
00004  * 
00005  *  @date Sun Feb 01 2004
00006  * 
00007  *  @version $Header: /export/cvs-gridlab/wp-1/Codes/GATEngine/C-reference/test/internal/gatrequest_tests.c,v 1.8 2004/04/20 17:04:43 hartmutkaiser Exp $
00008  *
00009  *  Copyright (C) Hartmut Kaiser
00010  *  This file is part of the GAT Engine.
00011  *  Contributed by Hartmut Kaiser <hartmutkaiser [at] t-online [dot] de>.
00012  *
00013  *  Use, modification and distribution is subject to the Gridlab Software
00014  *  License. (See accompanying file GLlicense.txt or copy at
00015  *  http://www.gridlab.org/GLlicense.txt)
00016  */
00017 
00018 static const char *rcsid = "$Header: /export/cvs-gridlab/wp-1/Codes/GATEngine/C-reference/test/internal/gatrequest_tests.c,v 1.8 2004/04/20 17:04:43 hartmutkaiser Exp $";
00019 
00020 /* System Header Files */
00021 
00022 #include <stdio.h>
00023 #include <stdlib.h>
00024 #include <unistd.h>
00025 
00026 /* GAT Header Files */
00027 
00028 #include "GAT.h"
00029 #include "GATTestUtils.h"
00030 
00031 /* Macros */
00032 
00033 /* Structures, unions and enums */
00034 
00035 /* Static function prototypes */
00036 static GATResult 
00037   on_checkpoint_issued_1(void *context_data, GATRequest_const request);
00038 
00039 static GATResult 
00040   on_checkpoint_issued_2(void *context_data, GATRequest_const request);
00041 
00042 /* File scope variables */
00043 
00044 /* External functions */
00045 
00046 int 
00047 main(int argc, const char * const argv[])
00048 {
00049   GATResult  retcode      = GAT_SUCCESS;
00050   GATContext context      = NULL;
00051   GATuint32  cookie_1     = 0;
00052   GATBool    break_loop_1 = GATFalse;
00053   int        i;
00054   int        ok = 0;
00055   
00056   GAT_TEST_INIT(-1);
00057   GAT_TEST_SUITE("GATRequest");
00058 
00059   context = GATContext_Create();
00060   GAT_TEST(NULL != context);
00061   
00062   /* the following test makes sure, that there were no errors during the 
00063      creation of the GATContext object */
00064   GAT_TEST_TRACE(GATType_GATContext == GATContext_GetType(context), context);
00065 
00066   GAT_TEST_START("GATRequest listener test");
00067   
00068   retcode = GATSelf_AddRequestListener(context, on_checkpoint_issued_1, 
00069     &break_loop_1, GATRequestType_Command, NULL, "checkpoint1", &cookie_1);
00070 
00071   GAT_TEST_TRACE(GAT_SUCCEEDED(retcode) && 0 != cookie_1, context);
00072 
00073   /* this for loop waits for the adaptor to fire the on_checkpoint_issued */
00074   for (i = 0; i < 5; i++ )
00075   {
00076     retcode = GATContext_ServiceActions (context, 0);
00077 
00078     if (GAT_FAILED(retcode) || GATTrue == break_loop_1)
00079     {
00080       ok = 1;
00081       break;
00082     }
00083     sleep (1);
00084   }
00085 
00086   GAT_TEST_TRACE(0 != ok, context);
00087   GAT_TEST_TRACE(GAT_SUCCEEDED(retcode), context);
00088     
00089   retcode = GATSelf_RemoveRequestListener(context, cookie_1);
00090   GAT_TEST_TRACE(GAT_SUCCEEDED(retcode), context);
00091   
00092   GAT_TEST_STOP();
00093   
00094   GATContext_Destroy(&context);
00095   
00096   GAT_TEST_FINISH();
00097   
00098   return 0;
00099 }
00100 
00101 /* This is the GATRequestListener, which get's called, whenever the 
00102    "checkpoint" command is issued */
00103 static GATResult
00104 on_checkpoint_issued_1(void *context_data, GATRequest_const request)
00105 {
00106   GATResult retval = GAT_INVALID_HANDLE;
00107 
00108   fprintf (stderr, "checkpoint now!\n");
00109   if (NULL != request)
00110   {
00111     GATRequestNotifier_const notifier = NULL;
00112     
00113     retval = GATRequest_GetRequestNotifier(request, &notifier);
00114     GAT_TEST(GAT_SUCCEEDED(retval));
00115     
00116     if (NULL != notifier)
00117     {
00118       GATTable table = GATTable_Create();
00119       
00120       GAT_TEST(NULL != table);
00121       
00122       /* add the name of the checkpoint file to the table */
00123       retval = GATTable_Add_String(table, "checkpoint_file1", "some_name");
00124       GAT_TEST(GAT_SUCCEEDED(retval));
00125       
00126       /* send the notifiertable back to the adaptor */
00127       retval = GATRequestNotifier_Respond(notifier, table);
00128       GAT_TEST(GAT_SUCCEEDED(retval));
00129       
00130       GATTable_Destroy(&table);
00131     }
00132     else
00133     {
00134       retval = GAT_FAIL;    /* completely unexpected */
00135     }
00136   }
00137   
00138   if (NULL != context_data)
00139   {
00140     *(GATBool *)context_data = GATTrue;   /* break the forever loop above */
00141   }
00142   return retval;
00143 }