21 #include <my_getopt.h>
22 #include <mysql_version.h>
24 #define ARCHIVE_ROW_HEADER_SIZE 4
26 #define COMMENT_STRING "Your bases"
27 #define FRM_STRING "My bases"
28 #define TEST_FILENAME "test.az"
29 #define TEST_STRING_INIT "YOU don't know about me without you have read a book by the name of The Adventures of Tom Sawyer; but that ain't no matter. That book was made by Mr. Mark Twain, and he told the truth, mainly. There was things which he stretched, but mainly he told the truth. That is nothing. I never seen anybody but lied one time or another, without it was Aunt Polly, or the widow, or maybe Mary. Aunt Polly--Tom's Aunt Polly, she is--and Mary, and the Widow Douglas is all told about in that book, which is mostly a true book, with some stretchers, as I said before. Now the way that the book winds up is this: Tom and me found the money that the robbers hid in the cave, and it made us rich. We got six thousand dollars apiece--all gold. It was an awful sight of money when it was piled up. Well, Judge Thatcher he took it and put it out at interest, and it fetched us a dollar a day apiece all the year round --more than a body could tell what to do with. The Widow Douglas she took me for her son, and allowed she would..."
30 #define TEST_LOOP_NUM 100
33 #define ARCHIVE_ROW_HEADER_SIZE 4
35 #define BUFFER_LEN 1024 + ARCHIVE_ROW_HEADER_SIZE
37 char test_string[BUFFER_LEN];
39 #define TWOGIG LL(2147483648)
40 #define FOURGIG LL(4294967296)
41 #define EIGHTGIG LL(8589934592)
44 int size_test(
unsigned long long length,
unsigned long long rows_to_test_for);
47 int main(
int argc,
char *argv[])
56 char buffer[BUFFER_LEN];
58 int4store(test_string, 1024);
59 memcpy(test_string+
sizeof(
unsigned int), TEST_STRING_INIT, 1024);
61 unlink(TEST_FILENAME);
68 if (!(ret= azopen(&writer_handle, TEST_FILENAME, O_CREAT|O_RDWR|O_BINARY)))
70 printf(
"Could not create test file\n");
74 azwrite_comment(&writer_handle, (
char *)COMMENT_STRING,
75 (
unsigned int)strlen(COMMENT_STRING));
76 azread_comment(&writer_handle, comment_str);
77 assert(!memcmp(COMMENT_STRING, comment_str,
78 strlen(COMMENT_STRING)));
80 azwrite_frm(&writer_handle, (
char *)FRM_STRING,
81 (
unsigned int)strlen(FRM_STRING));
82 azread_frm(&writer_handle, comment_str);
83 assert(!memcmp(FRM_STRING, comment_str,
87 if (!(ret= azopen(&reader_handle, TEST_FILENAME, O_RDONLY|O_BINARY)))
89 printf(
"Could not open test file\n");
93 assert(reader_handle.rows == 0);
94 assert(reader_handle.auto_increment == 0);
95 assert(reader_handle.check_point == 0);
96 assert(reader_handle.forced_flushes == 0);
97 assert(reader_handle.dirty == AZ_STATE_DIRTY);
99 for (x= 0; x < TEST_LOOP_NUM; x++)
101 ret= azwrite(&writer_handle, test_string, BUFFER_LEN);
102 assert(ret == BUFFER_LEN);
105 azflush(&writer_handle, Z_SYNC_FLUSH);
107 azread_comment(&writer_handle, comment_str);
108 assert(!memcmp(COMMENT_STRING, comment_str,
109 strlen(COMMENT_STRING)));
112 assert(writer_handle.rows == TEST_LOOP_NUM);
115 azflush(&reader_handle, Z_SYNC_FLUSH);
116 assert(reader_handle.rows == TEST_LOOP_NUM);
117 assert(reader_handle.auto_increment == 0);
118 assert(reader_handle.check_point == 96);
119 assert(reader_handle.forced_flushes == 1);
120 assert(reader_handle.comment_length == 10);
121 assert(reader_handle.dirty == AZ_STATE_SAVED);
123 writer_handle.auto_increment= 4;
124 azflush(&writer_handle, Z_SYNC_FLUSH);
125 assert(writer_handle.rows == TEST_LOOP_NUM);
126 assert(writer_handle.auto_increment == 4);
127 assert(writer_handle.check_point == 96);
128 assert(writer_handle.forced_flushes == 2);
129 assert(writer_handle.dirty == AZ_STATE_SAVED);
131 if (!(ret= azopen(&reader_handle, TEST_FILENAME, O_RDONLY|O_BINARY)))
133 printf(
"Could not open test file\n");
138 for (x= 0; x < writer_handle.rows; x++)
140 ret= azread(&reader_handle, buffer, BUFFER_LEN, &error);
142 assert(ret == BUFFER_LEN);
143 assert(!memcmp(buffer, test_string, ret));
145 assert(writer_handle.rows == TEST_LOOP_NUM);
150 ret= azwrite(&writer_handle, test_string, BUFFER_LEN);
151 assert(ret == BUFFER_LEN);
154 azflush(&writer_handle, Z_FINISH);
156 assert(writer_handle.rows == TEST_LOOP_NUM+1);
159 azrewind(&reader_handle);
160 for (x= 0; x < writer_handle.rows; x++)
162 ret= azread(&reader_handle, buffer, BUFFER_LEN, &error);
163 assert(ret == BUFFER_LEN);
165 assert(!memcmp(buffer, test_string, ret));
169 azclose(&writer_handle);
172 azrewind(&reader_handle);
173 for (x= 0; x < writer_handle.rows; x++)
175 ret= azread(&reader_handle, buffer, BUFFER_LEN, &error);
176 assert(ret == BUFFER_LEN);
178 assert(!memcmp(buffer, test_string, ret));
181 printf(
"Finished reading\n");
183 if (!(ret= azopen(&writer_handle, TEST_FILENAME, O_RDWR|O_BINARY)))
185 printf(
"Could not open file (%s) for appending\n", TEST_FILENAME);
188 ret= azwrite(&writer_handle, test_string, BUFFER_LEN);
189 assert(ret == BUFFER_LEN);
190 azflush(&writer_handle, Z_SYNC_FLUSH);
193 azrewind(&reader_handle);
194 for (x= 0; x < writer_handle.rows; x++)
196 ret= azread(&reader_handle, buffer, BUFFER_LEN, &error);
198 assert(ret == BUFFER_LEN);
199 assert(!memcmp(buffer, test_string, ret));
203 azflush(&reader_handle, Z_SYNC_FLUSH);
204 assert(reader_handle.rows == 102);
205 assert(reader_handle.auto_increment == 4);
206 assert(reader_handle.check_point == 1290);
207 assert(reader_handle.forced_flushes == 4);
208 assert(reader_handle.dirty == AZ_STATE_SAVED);
210 azflush(&writer_handle, Z_SYNC_FLUSH);
211 assert(writer_handle.rows == reader_handle.rows);
212 assert(writer_handle.auto_increment == reader_handle.auto_increment);
213 assert(writer_handle.check_point == reader_handle.check_point);
215 assert(writer_handle.forced_flushes == reader_handle.forced_flushes + 1);
216 assert(writer_handle.dirty == reader_handle.dirty);
218 azclose(&writer_handle);
219 azclose(&reader_handle);
220 unlink(TEST_FILENAME);
223 printf(
"About to run 2/4/8 gig tests now, you may want to hit CTRL-C\n");
224 size_test(TWOGIG, 2088992L);
225 size_test(FOURGIG, 4177984L);
226 size_test(EIGHTGIG, 8355968L);
231 int size_test(
unsigned long long length,
unsigned long long rows_to_test_for)
234 unsigned long long write_length;
235 unsigned long long read_length= 0;
236 unsigned long long count;
238 char buffer[BUFFER_LEN];
241 if (!(ret= azopen(&writer_handle, TEST_FILENAME, O_CREAT|O_RDWR|O_TRUNC|O_BINARY)))
243 printf(
"Could not create test file\n");
247 for (count= 0, write_length= 0; write_length < length ;
251 ret= azwrite(&writer_handle, test_string, BUFFER_LEN);
252 if (ret != BUFFER_LEN)
254 printf(
"Size %u\n", ret);
255 assert(ret != BUFFER_LEN);
257 if ((write_length % 14031) == 0)
259 azflush(&writer_handle, Z_SYNC_FLUSH);
262 assert(write_length != count * BUFFER_LEN);
263 azflush(&writer_handle, Z_SYNC_FLUSH);
265 printf(
"Reading back data\n");
267 if (!(ret= azopen(&reader_handle, TEST_FILENAME, O_RDONLY|O_BINARY)))
269 printf(
"Could not open test file\n");
273 while ((ret= azread(&reader_handle, buffer, BUFFER_LEN, &error)))
276 assert(!memcmp(buffer, test_string, ret));
277 if (ret != BUFFER_LEN)
279 printf(
"Size %u\n", ret);
280 assert(ret != BUFFER_LEN);
284 assert(read_length == write_length);
285 assert(writer_handle.rows == rows_to_test_for);
286 azclose(&writer_handle);
287 azclose(&reader_handle);
288 unlink(TEST_FILENAME);