Просмотр исходного кода

Test expiration timer.

(Logical change 1.80)


git-svn-id: http://svn.fedorahosted.org/svn/corosync/trunk@285 fd59a12c-fef9-0310-b244-a6a79926bd2f
Steven Dake 21 лет назад
Родитель
Сommit
f2fca925bc
1 измененных файлов с 34 добавлено и 7 удалено
  1. 34 7
      test/testckpt.c

+ 34 - 7
test/testckpt.c

@@ -1,3 +1,4 @@
+#define _BSD_SOURCE
 /*
 /*
  * Copyright (c) 2002-2004 MontaVista Software, Inc.
  * Copyright (c) 2002-2004 MontaVista Software, Inc.
  *
  *
@@ -40,10 +41,13 @@
 #include <sys/socket.h>
 #include <sys/socket.h>
 #include <sys/select.h>
 #include <sys/select.h>
 #include <sys/un.h>
 #include <sys/un.h>
+#include <sys/time.h>
 
 
 #include "ais_types.h"
 #include "ais_types.h"
 #include "ais_ckpt.h"
 #include "ais_ckpt.h"
 
 
+#define SECONDS_TO_EXPIRE 4
+
 int ckptinv;
 int ckptinv;
 void printSaNameT (SaNameT *name)
 void printSaNameT (SaNameT *name)
 {
 {
@@ -61,7 +65,7 @@ SaNameT checkpointName = { 5, "abra\0" };
 SaCkptCheckpointCreationAttributesT checkpointCreationAttributes = {
 SaCkptCheckpointCreationAttributesT checkpointCreationAttributes = {
 	SA_CKPT_WR_ALL_REPLICAS,
 	SA_CKPT_WR_ALL_REPLICAS,
 	100000,
 	100000,
-	0,
+	5000000000,
 	5,
 	5,
 	20000,
 	20000,
 	10
 	10
@@ -78,12 +82,12 @@ SaCkptSectionIdT sectionId2 = {
 };
 };
 SaCkptSectionCreationAttributesT sectionCreationAttributes1 = {
 SaCkptSectionCreationAttributesT sectionCreationAttributes1 = {
 	&sectionId1,
 	&sectionId1,
-	0xFFFFFFFF
+	SA_TIME_END
 };
 };
 
 
 SaCkptSectionCreationAttributesT sectionCreationAttributes2 = {
 SaCkptSectionCreationAttributesT sectionCreationAttributes2 = {
 	&sectionId2,
 	&sectionId2,
-	0xFFFFFFFF
+	SA_TIME_END
 };
 };
 
 
 char readBuffer1[1025];
 char readBuffer1[1025];
@@ -149,6 +153,9 @@ int main (void) {
 	SaCkptSectionDescriptorT sectionDescriptor;
 	SaCkptSectionDescriptorT sectionDescriptor;
 	SaUint32T erroroneousVectorIndex = 0;
 	SaUint32T erroroneousVectorIndex = 0;
 	SaErrorT error;
 	SaErrorT error;
+	struct timeval tv_start;
+	struct timeval tv_end;
+	struct timeval tv_elapsed;
 	
 	
 	error = saCkptCheckpointOpen (&checkpointName,
 	error = saCkptCheckpointOpen (&checkpointName,
 		&checkpointCreationAttributes,
 		&checkpointCreationAttributes,
@@ -157,12 +164,31 @@ int main (void) {
 		&checkpointHandle);
 		&checkpointHandle);
 	printf ("first open result %d (should be 1)\n", error);
 	printf ("first open result %d (should be 1)\n", error);
 
 
-// start of stuff
+	gettimeofday (&tv_start, 0);
+	sectionCreationAttributes1.expirationTime = ((unsigned long long)(tv_start.tv_sec + SECONDS_TO_EXPIRE)) * ((unsigned long long)1000000000) + ((unsigned long long)(tv_start.tv_usec) * ((unsigned long long)1000));
+
 	error = saCkptSectionCreate (&checkpointHandle,
 	error = saCkptSectionCreate (&checkpointHandle,
 		&sectionCreationAttributes1,
 		&sectionCreationAttributes1,
 		"Initial Data #0",
 		"Initial Data #0",
 		strlen ("Initial Data #0") + 1);
 		strlen ("Initial Data #0") + 1);
+
 printf ("create1 error is %d\n", error);
 printf ("create1 error is %d\n", error);
+printf ("Please wait, testing expiry of checkpoint sections.\n");
+	do {
+	error = saCkptCheckpointRead (&checkpointHandle,
+		ReadVectorElements,
+		1,
+		&erroroneousVectorIndex);
+	} while (error != SA_ERR_NOT_EXIST);
+	gettimeofday (&tv_end, NULL);
+	timersub (&tv_end, &tv_start, &tv_elapsed);
+	printf ("Elapsed Time to expiry is %d.%d (should be about %d seconds)\n", tv_elapsed.tv_sec, tv_elapsed.tv_usec, SECONDS_TO_EXPIRE);
+
+	error = saCkptCheckpointRetentionDurationSet (&checkpointHandle,
+		5000000000);
+	printf ("RetentionDurationSet is %d\n", error);
+	exit (1);
+
 	error = saCkptSectionCreate (&checkpointHandle,
 	error = saCkptSectionCreate (&checkpointHandle,
 		&sectionCreationAttributes2,
 		&sectionCreationAttributes2,
 		"Initial Data #0",
 		"Initial Data #0",
@@ -215,7 +241,8 @@ exit (1);
 	printf ("open after unlink/close result %d (should be 1)\n", error);
 	printf ("open after unlink/close result %d (should be 1)\n", error);
 
 
 	error = saCkptCheckpointRetentionDurationSet (&checkpointHandle,
 	error = saCkptCheckpointRetentionDurationSet (&checkpointHandle,
-		10000);
+		5000000000);
+printf ("Retention duration set error is %d\n", error);
 	printf ("set checkpoint retention duration result %d (should be 1)\n", error);
 	printf ("set checkpoint retention duration result %d (should be 1)\n", error);
 
 
 	error = saCkptCheckpointStatusGet (&checkpointHandle,
 	error = saCkptCheckpointStatusGet (&checkpointHandle,
@@ -257,8 +284,8 @@ exit (1);
 #endif
 #endif
 
 
 	error = saCkptSectionExpirationTimeSet (&checkpointHandle,
 	error = saCkptSectionExpirationTimeSet (&checkpointHandle,
-		&sectionId1,
-		0xFFAAAAAA);
+		&sectionId2,
+		SA_TIME_END);
 	printf ("saCkptSectionExpirationTimeSet result %d (should be 1)\n", error);
 	printf ("saCkptSectionExpirationTimeSet result %d (should be 1)\n", error);