1 20 package com.presumo.jms.persistence; 21 22 import com.presumo.jms.message.JmsMessage; 23 import com.presumo.jms.message.JmsTextMessage; 24 import com.presumo.jms.message.JmsObjectMessage; 25 import com.presumo.jms.message.JmsBytesMessage; 26 import com.presumo.jms.message.JmsMapMessage; 27 import com.presumo.jms.message.JmsStreamMessage; 28 29 import java.io.File ; 30 import java.io.FileInputStream ; 31 import java.io.FileOutputStream ; 32 33 import java.util.Iterator ; 34 import java.util.LinkedList ; 35 import java.util.ListIterator ; 36 import java.util.Random ; 37 38 import junit.framework.Test; 39 import junit.framework.TestCase; 40 import junit.framework.TestSuite; 41 42 45 public class PersistentQueueTest extends TestCase 46 { 47 private static final Random random = new Random (); 48 private static boolean DEBUG = false; 49 50 private static void debug(Object obj) 51 { 52 if (DEBUG) { 53 System.out.println(obj); 54 } 55 } 56 57 public PersistentQueueTest(String name) 58 { 59 super(name); 60 } 61 62 63 public static Test suite() 64 { 65 TestSuite suite = new TestSuite(PersistentQueueTest.class); 66 return suite; 67 } 68 69 public void testPersistentQueue() throws Exception 70 { 71 String dir = "./logs/queuetest"; 72 TestOperation all_tests = makeTests(new File (dir)); 73 TestState state = new TestState(); 74 all_tests.operate(state); 75 } 76 77 78 79 80 private static class TestState 81 { 82 public int cur_value; 83 public PersistentQueue the_queue; 84 public LinkedList mainQueue; 85 public LinkedList pendingDelete; 86 public LinkedList deleted; 87 public LinkedList op_stack; 88 } 89 90 private static final int CP_FILE = 0; 91 private static final int TEMP_FILE = 1; 92 private static final int LOG_FILE = 2; 93 94 private static abstract class TestOperation 95 { 96 private void removeNonPersistent(LinkedList list) 97 { 98 ListIterator it = list.listIterator(0); 99 while (it.hasNext()) { 100 JmsMessage msg = (JmsMessage)it.next(); 101 if (! PersistentQueue.isMessagePersistent(msg)) { 102 it.remove(); 103 } 104 } 105 } 106 107 protected void removeNonPersistent(TestState st) 108 { 109 removeNonPersistent(st.mainQueue); 110 removeNonPersistent(st.pendingDelete); 111 removeNonPersistent(st.deleted); 112 } 113 114 protected File getFile(TestState state, int file_type) 115 { 116 File dir = state.the_queue.getDirectory(); 117 String pre = state.the_queue.getFilePrefix(); 118 String name = null; 119 switch (file_type) { 120 case CP_FILE: 121 name = PersistentQueue.CP_SUFFIX; 122 break; 123 case TEMP_FILE: 124 name = PersistentQueue.TEMP_CP_SUFFIX; 125 break; 126 case LOG_FILE: 127 name = PersistentQueue.LOG_SUFFIX; 128 break; 129 default: 130 throw new RuntimeException ("Unknown type"); 131 } 132 return new File (dir,pre+name); 133 } 134 135 protected void copyFile(File src, File dst) throws Exception 136 { 137 copyFile(src,dst,(int)src.length()); 138 } 139 140 protected void copyFile(File src, File dst, int size) throws Exception 141 { 142 FileInputStream in = null; 143 FileOutputStream out = null; 144 try { 145 in = new FileInputStream (src); 146 out = new FileOutputStream (dst); 147 for (int i = 0; i < size; i++) { 148 byte temp = (byte)in.read(); 149 out.write(temp); 150 } 151 } 152 finally { 153 if (in != null) 154 in.close(); 155 if (out != null) 156 out.close(); 157 } 158 } 159 160 protected void basicSanityCheck(TestState state) throws Exception 161 { 162 int act_num_pend = state.the_queue.getNumPendingDelete(); 163 int act_num_main = state.the_queue.getNumNotPendingDelete(); 164 int theory_num_main = state.mainQueue.size(); 165 int theory_num_pend = state.pendingDelete.size(); 166 if (act_num_pend != theory_num_pend) { 167 throw new Exception ("Failed pending sanity check: "+act_num_pend+" "+theory_num_pend); 168 } 169 if (act_num_main != theory_num_main) { 170 throw new Exception ("Failed main sanity check: "+act_num_main+" "+theory_num_main); 171 } 172 JmsMessage [] pd = state.the_queue.getPendingDelete(); 173 Iterator it = state.pendingDelete.iterator(); 174 for (int i = 0; i < pd.length; i++) { 175 JmsMessage msg = (JmsMessage)it.next(); 176 if (!pd[i].getJMSMessageID().equals(msg.getJMSMessageID())) { 177 throw new Exception ("Failed pd sanity check "+pd[i]+" "+msg); 178 } 179 } 180 } 181 182 183 protected String createRandomString() 184 { 185 return createRandomString(20); 186 } 187 protected String createRandomString(int maxsize) 188 { 189 int size = random.nextInt(maxsize)+1; 190 int lowchar = '0'; 191 int highchar = '~'; 192 int alpharange = highchar - lowchar; 193 194 byte [] b = new byte[size]; 195 for (int i=0; i < size; i++) { 196 b[i] = (byte)( random.nextInt(alpharange) + lowchar ); 197 } 198 return new String (b); 199 } 200 201 202 protected JmsMessage createMessage(int id, boolean persistent) 203 throws Exception 204 { 205 int messageType = random.nextInt(5); 206 207 JmsMessage message = null; 208 switch(messageType) { 209 case (0): message = createTextMessage(); break; 210 case (1): message = createObjectMessage(); break; 211 case (2): message = createBytesMessage(); break; 212 case (3): message = createMapMessage(); break; 213 case (4): message = createStreamMessage(); break; 214 default: 215 message = new JmsMessage("qt"); 216 } 217 218 int numProperties = random.nextInt(10); 219 for (int i=0; i < numProperties; i++) { 220 String key = createRandomString() + i; 221 String value = createRandomString(); 222 message.setStringProperty(key, value); 223 } 224 225 if (persistent) { 226 message.setJMSDeliveryMode(javax.jms.DeliveryMode.PERSISTENT); 227 } else { 228 message.setJMSDeliveryMode(javax.jms.DeliveryMode.NON_PERSISTENT); 229 } 230 231 return message; 232 } 233 234 private JmsMessage createTextMessage() throws Exception 235 { 236 JmsTextMessage msg = new JmsTextMessage("queuetest"); 237 msg.setText(createRandomString(50)); 238 return msg; 239 } 240 241 private JmsMessage createObjectMessage() throws Exception 242 { 243 JmsObjectMessage msg = new JmsObjectMessage("queuetest"); 244 msg.setObject(createRandomString(50)); 245 return msg; 246 } 247 248 private JmsMessage createBytesMessage() throws Exception 249 { 250 JmsBytesMessage msg = new JmsBytesMessage("queuetest"); 251 msg.writeObject(createRandomString(100)); 252 msg.writeObject(createRandomString(50)); 253 msg.writeInt(random.nextInt()); 254 return msg; 255 } 256 257 private JmsMessage createMapMessage() throws Exception 258 { 259 JmsMapMessage msg = new JmsMapMessage("queuetest"); 260 int numProperties = random.nextInt(10); 261 for (int i=0; i < numProperties; i++) { 262 String key = createRandomString() + i; 263 String value = createRandomString(); 264 msg.setObject(key, value); 265 } 266 return msg; 267 } 268 269 private JmsMessage createStreamMessage() throws Exception 270 { 271 JmsStreamMessage msg = new JmsStreamMessage("queuetest"); 272 msg.writeString(createRandomString(50)); 273 return msg; 274 } 275 276 public abstract void operate(TestState state) throws Exception ; 277 } 278 279 283 private static abstract class ReversibleTestOperation extends TestOperation 284 { 285 public abstract void undo(TestState state) throws Exception ; 286 } 287 288 private static _INIT INIT(File d, int m) 292 { 293 return new _INIT(d,m); 294 } 295 private static class _INIT extends TestOperation 296 { 297 private File directory; 298 private int max_log_file_size; 299 300 public _INIT(File directory, 301 int max_log_file_size) { 302 this.directory = directory; 303 this.max_log_file_size = max_log_file_size; 304 } 305 306 public void operate(TestState state) throws Exception { 307 state.the_queue = new PersistentQueue(directory, 308 "test", 309 max_log_file_size); 310 state.mainQueue = new LinkedList (); 311 state.pendingDelete = new LinkedList (); 312 state.op_stack = new LinkedList (); 313 state.deleted = new LinkedList (); 314 state.cur_value = 0; 315 } 316 } 317 318 319 private static _OPEN OPEN() { 323 return new _OPEN(); 324 } 325 private static class _OPEN extends TestOperation { 326 public void operate(TestState state) throws Exception { 327 state.the_queue.open(); 328 basicSanityCheck(state); 329 } 330 } 331 332 333 private static _CLOSE CLOSE() { 337 return new _CLOSE(); 338 } 339 private static class _CLOSE extends TestOperation { 340 public void operate(TestState state) throws Exception { 341 removeNonPersistent(state); 342 boolean empty = ( state.mainQueue.size() == 0 && 343 state.pendingDelete.size() == 0 ); 344 state.the_queue.close(); 345 if (empty && 346 (getFile(state,CP_FILE).exists() || 347 getFile(state,TEMP_FILE).exists() || 348 getFile(state,LOG_FILE).exists())) { 349 throw new Exception ("No files should exist"); 350 } 351 } 352 } 353 354 private static _FORCE_CP FORCE_CP() { 358 return new _FORCE_CP(); 359 } 360 private static class _FORCE_CP extends TestOperation { 361 public void operate(TestState state) throws Exception { 362 state.the_queue.forceCheckPoint(); 363 basicSanityCheck(state); 364 } 365 } 366 367 368 private static _SET_MAX_LOG_FILE_SIZE SET_MAX_LOG_FILE_SIZE(int s) { 372 return new _SET_MAX_LOG_FILE_SIZE(s); 373 } 374 private static class _SET_MAX_LOG_FILE_SIZE extends TestOperation { 375 private int size; 376 public _SET_MAX_LOG_FILE_SIZE(int size) { 377 this.size = size; 378 } 379 public void operate(TestState state) throws Exception { 380 state.the_queue.setMaxLogFileSize(size); 381 basicSanityCheck(state); 382 } 383 } 384 385 386 private static _PUSH PUSH(int num_persistent, 390 int num_non_persistent) { 391 return new _PUSH(num_persistent,num_non_persistent); 392 } 393 private static class _PUSH extends ReversibleTestOperation { 394 private int num_persistent,num_non_persistent; 395 public _PUSH(int num_per, 396 int num_non) { 397 num_persistent = num_per; 398 num_non_persistent = num_non; 399 } 400 public void operate(TestState state) throws Exception { 401 JmsMessage [] entries = new JmsMessage[num_persistent+num_non_persistent]; 402 for (int i = 0; i < num_persistent; i++) { 403 entries[i] = createMessage(state.cur_value++, true); 404 state.mainQueue.addLast(entries[i]); 405 } 406 for (int i = num_persistent; i < num_non_persistent+num_persistent; i++) { 407 entries[i] = createMessage(state.cur_value++, false); 408 state.mainQueue.addLast(entries[i]); 409 } 410 if (entries.length == 1) { 411 state.the_queue.push(entries[0]); 412 } 413 else { 414 state.the_queue.push(entries); 415 } 416 state.op_stack.addLast(this); 417 basicSanityCheck(state); 418 } 419 public void undo(TestState state) { 420 for (int i = 0; i < num_persistent+num_non_persistent; i++) { 421 state.mainQueue.removeLast(); 422 } 423 } 424 } 425 426 private static _DELETE DELETE(int n) { 430 return new _DELETE(n); 431 } 432 private static class _DELETE extends ReversibleTestOperation { 433 private int num_to_delete; 434 public _DELETE(int num_to_delete) { 435 this.num_to_delete = num_to_delete; 436 } 437 public void operate(TestState state) throws Exception { 438 String [] del = new String [num_to_delete]; 439 Iterator it = state.pendingDelete.iterator(); 440 for (int i = 0; i < num_to_delete; i++) { 441 JmsMessage msg = (JmsMessage)it.next(); 442 del[i] = msg.getJMSMessageID(); 443 it.remove(); 444 state.deleted.addLast(msg); 445 } 446 447 if (del.length == 1) { 448 state.the_queue.delete(del[0]); 449 } 450 else { 451 state.the_queue.delete(del); 452 } 453 state.op_stack.addLast(this); 454 basicSanityCheck(state); 455 } 456 public void undo(TestState state) throws Exception { 457 for (int i = 0; i < num_to_delete; i++) { 458 Object ent = state.deleted.removeLast(); 459 state.pendingDelete.addFirst(ent); 460 } 461 } 462 } 463 464 private static _GET_NEXT GET_NEXT(int n) { 468 return new _GET_NEXT(n); 469 } 470 private static class _GET_NEXT extends ReversibleTestOperation { 471 private int num_to_get; 472 public _GET_NEXT(int num_to_get) { 473 this.num_to_get = num_to_get; 474 } 475 public void operate(TestState state) throws Exception { 476 int num_should_get = num_to_get; 477 if (num_should_get > state.mainQueue.size()) 478 num_should_get = state.mainQueue.size(); 479 JmsMessage [] msgs = state.the_queue.getNext(num_to_get); 480 if (msgs.length != num_should_get) { 481 throw new Exception ("Unexpected number returned "+msgs.length+" "+num_should_get); 482 } 483 ListIterator it = state.mainQueue.listIterator(); 484 for (int i = 0; i < msgs.length; i++) { 485 debug("Reading value: " + msgs[i]); 486 487 JmsMessage message = (JmsMessage)it.next(); 488 if (!message.getJMSMessageID().equals(msgs[i].getJMSMessageID())) { 489 throw new Exception ("Bad data read from queue "+message+" "+msgs[i]); 490 } 491 it.remove(); 492 493 if (PersistentQueue.isMessagePersistent(message)) { 496 state.pendingDelete.addLast(message); 497 } 498 } 499 state.op_stack.addLast(this); 500 basicSanityCheck(state); 501 } 502 public void undo(TestState state) throws Exception { 503 for (int i = 0; i < num_to_get; i++) { 504 Object ent = state.pendingDelete.removeLast(); 505 state.mainQueue.addFirst(ent); 506 } 507 } 508 } 509 510 511 private static _CORRUPT_FILE CORRUPT_FILE(int fi) { 515 return new _CORRUPT_FILE(fi); 516 } 517 private static class _CORRUPT_FILE extends TestOperation { 518 private int file_id; 519 public _CORRUPT_FILE(int file_id) { 520 this.file_id = file_id; 521 } 522 public void operate(TestState state) throws Exception { 523 525 File the_file = getFile(state,file_id); 526 File temp = File.createTempFile("prefix","suffix"); 527 copyFile(the_file,temp); 528 copyFile(temp,the_file,(int)(temp.length()-1)); 529 if (!temp.delete()) 530 throw new Exception ("Couldn't delete"+temp); 531 if (file_id == LOG_FILE) { 532 ReversibleTestOperation rop = (ReversibleTestOperation)state.op_stack.removeLast(); 533 rop.undo(state); 534 } 535 } 536 } 537 538 539 private static _COPY_FILE COPY_FILE(int src,int dest) { 543 return new _COPY_FILE(src,dest); 544 } 545 private static class _COPY_FILE extends TestOperation { 546 private int src,dest; 547 _COPY_FILE(int src, int dest) { 548 this.src = src; 549 this.dest = dest; 550 } 551 public void operate(TestState state) throws Exception { 552 copyFile(getFile(state,src),getFile(state,dest)); 553 } 554 } 555 556 557 private static _CREATE_FILE CREATE_FILE(int fi) { 561 return new _CREATE_FILE(fi); 562 } 563 private static class _CREATE_FILE extends TestOperation { 564 private int file_id; 565 public _CREATE_FILE(int file_id) { 566 this.file_id = file_id; 567 } 568 public void operate(TestState state) throws Exception { 569 File the_file = getFile(state,file_id); 570 debug("Creating "+the_file); 571 572 FileOutputStream out = new FileOutputStream (the_file); 573 out.close(); 574 } 575 } 576 577 578 private static _DELETE_FILE DELETE_FILE(int fi) { 582 return new _DELETE_FILE(fi); 583 } 584 private static class _DELETE_FILE extends TestOperation { 585 private int file_id; 586 public _DELETE_FILE(int file_id) { 587 this.file_id = file_id; 588 } 589 public void operate(TestState state) throws Exception { 590 File the_file = getFile(state,file_id); 591 debug("Deleting "+the_file); 592 593 if (!the_file.delete()) { 594 throw new Exception ("Couldn't delete "+the_file); 595 } 596 } 597 } 598 599 600 private static _REPEAT REPEAT(TestOperation o, 604 int n) { 605 return new _REPEAT(o,n); 606 } 607 private static class _REPEAT extends TestOperation { 608 private TestOperation the_op; 609 private int num_times; 610 public _REPEAT(TestOperation the_op, 611 int num_times) { 612 this.the_op = the_op; 613 this.num_times = num_times; 614 } 615 public void operate(TestState state) throws Exception { 616 for (int i = 0; i < num_times; i++) { 617 the_op.operate(state); 618 } 619 } 620 } 621 622 private static _SEQUENCE SEQUENCE(TestOperation op1, 626 TestOperation op2) { 627 return new _SEQUENCE(op1,op2); 628 } 629 private static _SEQUENCE SEQUENCE(TestOperation op1, 630 TestOperation op2, 631 TestOperation op3) { 632 return SEQUENCE(SEQUENCE(op1,op2),op3); 633 } 634 private static _SEQUENCE SEQUENCE(TestOperation op1, 635 TestOperation op2, 636 TestOperation op3, 637 TestOperation op4) { 638 return SEQUENCE(SEQUENCE(op1,op2,op3),op4); 639 } 640 private static _SEQUENCE SEQUENCE(TestOperation op1, 641 TestOperation op2, 642 TestOperation op3, 643 TestOperation op4, 644 TestOperation op5) { 645 return SEQUENCE(SEQUENCE(op1,op2,op3,op4),op5); 646 } 647 private static _SEQUENCE SEQUENCE(TestOperation op1, 648 TestOperation op2, 649 TestOperation op3, 650 TestOperation op4, 651 TestOperation op5, 652 TestOperation op6) { 653 return SEQUENCE(SEQUENCE(op1,op2,op3,op4,op5),op6); 654 } 655 private static _SEQUENCE SEQUENCE(TestOperation op1, 656 TestOperation op2, 657 TestOperation op3, 658 TestOperation op4, 659 TestOperation op5, 660 TestOperation op6, 661 TestOperation op7) { 662 return SEQUENCE(SEQUENCE(op1,op2,op3,op4,op5,op6),op7); 663 } 664 665 private static _SEQUENCE SEQUENCE(TestOperation op1, 666 TestOperation op2, 667 TestOperation op3, 668 TestOperation op4, 669 TestOperation op5, 670 TestOperation op6, 671 TestOperation op7, 672 TestOperation op8) { 673 return SEQUENCE(SEQUENCE(op1,op2,op3,op4,op5,op6,op7),op8); 674 } 675 private static _SEQUENCE SEQUENCE(TestOperation op1, 676 TestOperation op2, 677 TestOperation op3, 678 TestOperation op4, 679 TestOperation op5, 680 TestOperation op6, 681 TestOperation op7, 682 TestOperation op8, 683 TestOperation op9) { 684 return SEQUENCE(SEQUENCE(op1,op2,op3,op4,op5,op6,op7,op8),op9); 685 } 686 private static _SEQUENCE SEQUENCE(TestOperation op1, 687 TestOperation op2, 688 TestOperation op3, 689 TestOperation op4, 690 TestOperation op5, 691 TestOperation op6, 692 TestOperation op7, 693 TestOperation op8, 694 TestOperation op9, 695 TestOperation op10) { 696 return SEQUENCE(SEQUENCE(op1,op2,op3,op4,op5,op6,op7,op8,op9),op10); 697 } 698 private static _SEQUENCE SEQUENCE(TestOperation op1, 699 TestOperation op2, 700 TestOperation op3, 701 TestOperation op4, 702 TestOperation op5, 703 TestOperation op6, 704 TestOperation op7, 705 TestOperation op8, 706 TestOperation op9, 707 TestOperation op10, 708 TestOperation op11) { 709 return SEQUENCE(SEQUENCE(op1,op2,op3,op4,op5,op6,op7,op8,op9,op10),op11); 710 } 711 private static _SEQUENCE SEQUENCE(TestOperation op1, 712 TestOperation op2, 713 TestOperation op3, 714 TestOperation op4, 715 TestOperation op5, 716 TestOperation op6, 717 TestOperation op7, 718 TestOperation op8, 719 TestOperation op9, 720 TestOperation op10, 721 TestOperation op11, 722 TestOperation op12) { 723 return SEQUENCE(SEQUENCE(op1,op2,op3,op4,op5,op6,op7,op8,op9,op10,op11),op12); 724 } 725 726 private static class _SEQUENCE extends TestOperation { 727 private TestOperation op1, op2; 728 public _SEQUENCE(TestOperation op1, TestOperation op2) { 729 this.op1 = op1; 730 this.op2 = op2; 731 } 732 public void operate(TestState state) throws Exception { 733 op1.operate(state); 734 op2.operate(state); 735 } 736 } 737 738 739 740 private static TestOperation makeTests(File directory) { 741 742 TestOperation BASIC_TEST = 743 SEQUENCE(INIT(directory, 744 10000), 745 OPEN(), 746 REPEAT(PUSH(5,5),10), 747 REPEAT(PUSH(10,10),20), 748 REPEAT(GET_NEXT(10),10), 749 REPEAT(PUSH(15,15),20), 750 REPEAT(DELETE(5),10), 751 GET_NEXT(1000), 752 DELETE(500), 753 CLOSE()); 754 TestOperation LOG_FILE_TEST = 755 SEQUENCE(INIT(directory, 756 1000000), 757 OPEN(), 758 REPEAT(PUSH(7,3),10), 759 FORCE_CP(), 760 REPEAT(GET_NEXT(10),10), 761 REPEAT(PUSH(8,0),10), 762 REPEAT(DELETE(7),10), 763 SEQUENCE(CLOSE(), 764 OPEN(), 765 GET_NEXT(40), 766 DELETE(40)), 767 SEQUENCE(CLOSE(), 768 OPEN(), 769 GET_NEXT(40), 770 DELETE(40)), 771 CLOSE()); 772 773 TestOperation ALL_NON_PERSISTENT_TEST = 774 SEQUENCE(INIT(directory, 775 100000), 776 OPEN(), 777 REPEAT(PUSH(0,100),100), 778 REPEAT(GET_NEXT(100),100), 779 CLOSE()); 780 TestOperation VERIFY_RECOVERS = 781 SEQUENCE(PUSH(10,0), 782 GET_NEXT(5), 783 DELETE(5), 784 CLOSE(), 785 OPEN(), 786 GET_NEXT(5), 787 DELETE(5), 788 CLOSE()); 789 TestOperation START_CREATING_CP_GOOD = 791 SEQUENCE(INIT(directory, 792 100000), 793 OPEN(), 794 PUSH(1,0), 795 FORCE_CP(), 796 CLOSE(), 797 DELETE_FILE(LOG_FILE), 798 OPEN(), 799 GET_NEXT(1), 800 DELETE(1), 801 VERIFY_RECOVERS); 802 TestOperation START_CREATING_CP_BAD = 803 SEQUENCE(INIT(directory, 804 100000), 805 CREATE_FILE(CP_FILE), 806 OPEN(), 807 VERIFY_RECOVERS); 808 TestOperation START_READY_CP_BAD = 810 SEQUENCE(INIT(directory, 811 100000), 812 OPEN(), 813 REPEAT(PUSH(2,0),3), 814 CLOSE(), 815 CORRUPT_FILE(LOG_FILE), 816 OPEN(), 817 GET_NEXT(4), 818 DELETE(4), 819 VERIFY_RECOVERS); 820 TestOperation START_CREATING_TEMP_GOOD = 822 SEQUENCE(INIT(directory, 823 100000), 824 OPEN(), 825 PUSH(1,0), 826 FORCE_CP(), 827 CLOSE(), 828 COPY_FILE(CP_FILE,TEMP_FILE), 829 OPEN(), 830 GET_NEXT(1), 831 DELETE(1), 832 VERIFY_RECOVERS); 833 TestOperation START_CREATING_TEMP_BAD = 834 SEQUENCE(INIT(directory, 835 100000), 836 OPEN(), 837 PUSH(1,0), 838 FORCE_CP(), 839 CLOSE(), 840 COPY_FILE(CP_FILE,TEMP_FILE), 841 CORRUPT_FILE(TEMP_FILE), 842 OPEN(), 843 GET_NEXT(1), 844 DELETE(1), 845 VERIFY_RECOVERS); 846 TestOperation START_TEMP_CORRECT_1 = 848 SEQUENCE(INIT(directory,100000), 849 OPEN(), 850 PUSH(1,0), 851 FORCE_CP(), 852 CLOSE(), 853 COPY_FILE(CP_FILE,TEMP_FILE), 854 DELETE_FILE(CP_FILE), 855 OPEN(), 856 GET_NEXT(1), 857 DELETE(1), 858 VERIFY_RECOVERS); 859 TestOperation START_TEMP_CORRECT_2 = 861 SEQUENCE(INIT(directory,100000), 862 OPEN(), 863 PUSH(1,0), 864 FORCE_CP(), 865 CLOSE(), 866 COPY_FILE(CP_FILE,TEMP_FILE), 867 DELETE_FILE(CP_FILE), 868 DELETE_FILE(LOG_FILE), 869 OPEN(), 870 GET_NEXT(1), 871 DELETE(1), 872 VERIFY_RECOVERS); 873 TestOperation START_COPYING_TO_CP_GOOD = 875 SEQUENCE(INIT(directory,100000), 876 OPEN(), 877 PUSH(1,0), 878 FORCE_CP(), 879 CLOSE(), 880 SEQUENCE(COPY_FILE(CP_FILE,TEMP_FILE), 881 DELETE_FILE(CP_FILE), 882 DELETE_FILE(LOG_FILE), 883 COPY_FILE(TEMP_FILE,CP_FILE)), 884 OPEN(), 885 GET_NEXT(1), 886 DELETE(1), 887 VERIFY_RECOVERS); 888 TestOperation START_COPYING_TO_CP_BAD = 889 SEQUENCE(INIT(directory,100000), 890 OPEN(), 891 PUSH(1,0), 892 FORCE_CP(), 893 CLOSE(), 894 SEQUENCE(COPY_FILE(CP_FILE,TEMP_FILE), 895 DELETE_FILE(CP_FILE), 896 DELETE_FILE(LOG_FILE), 897 COPY_FILE(TEMP_FILE,CP_FILE), 898 CORRUPT_FILE(CP_FILE)), 899 OPEN(), 900 GET_NEXT(1), 901 DELETE(1), 902 VERIFY_RECOVERS); 903 904 return SEQUENCE(BASIC_TEST, 905 LOG_FILE_TEST, 906 ALL_NON_PERSISTENT_TEST, 907 START_CREATING_CP_GOOD, 908 START_CREATING_CP_BAD, 909 START_READY_CP_BAD, 910 START_CREATING_TEMP_GOOD, 911 START_CREATING_TEMP_BAD, 912 START_TEMP_CORRECT_1, 913 START_TEMP_CORRECT_2, 914 START_COPYING_TO_CP_GOOD, 915 START_COPYING_TO_CP_BAD); 916 } 917 918 public static void main(String [] args) throws Exception { 919 boolean logging = false; 920 String dir = null; 921 if (args.length > 1 || args[0].equals("-verbose")) { 922 DEBUG = true; 923 dir = args[1]; 924 } 925 else { 926 dir = args[0]; 927 } 928 TestOperation all_tests = makeTests(new File (dir)); 929 TestState state = new TestState(); 930 all_tests.operate(state); 931 debug("SUCCESS"); 932 } 933 } 934 | Popular Tags |