659 tests.put(tr.getWorkRelativePath(), tr);
660 totalEntryCount++; // count all entries, including duplicates
661 }
662 lastFileSize = raf.length();
663 return tests;
664 }
665
666 //-------------------------------------------------------------------------------------
667 //
668 // Write the cache
669
670 private void writeCache(Map<String, TestResult> tests) throws IOException {
671 if (tests == null)
672 throw new IllegalStateException();
673
674 // merge any tests in testsToWrite
675 // testsToWrite is a thread-safe fifo, so it is safe to keep reading
676 // it till its empty, even though some tests may even have been added
677 // after the worker woke up
678 TestResult tr;
679 while ((tr = (TestResult) (testsToWrite.remove())) != null) {
680 // check if test is in the set we've just read
681 String name = tr.getTestName();
682 TestResult tr2 = tests.get(name);
683 // if the cache file contains a conflicting entry,
684 // reload the test from the .jtr file; otherwise, add it to the cache
685 if (tr2 != null && !tr2.getStatus().equals(tr.getStatus()))
686 reload(tests, tr);
687 else
688 tests.put(tr.getWorkRelativePath(), tr);
689 }
690
691 // write cache
692 raf.seek(0);
693 long now = System.currentTimeMillis();
694 lastSerial = (int) ((now >> 16) + (now & 0xffff));
695 raf.writeInt(lastSerial);
696
697 for (Iterator iter = tests.values().iterator(); iter.hasNext(); ) {
698 tr = (TestResult) (iter.next());
699 writeCacheEntry(tr);
700 }
701
702 if (DEBUG_WORK)
703 Debug.println("TRC.writeCache write all (" + tests.size() + " tests)");
704
705 raf.setLength(raf.getFilePointer());
706 lastFileSize = raf.length();
707 uniqueInitialEntryCount = totalEntryCount = tests.size();
708 }
709
710 private void updateCache(Map<String, TestResult> tests) throws IOException {
711 // testsToWrite is a thread-safe fifo, so it is safe to keep reading
712 // it till its empty, even though some tests may even have been added
713 // after the worker woke up
714 int debugCount = 0;
715 raf.seek(lastFileSize);
716 TestResult tr;
717 while ((tr = (TestResult) (testsToWrite.remove())) != null) {
718 if (tests != null) {
719 // check if test is in the set we've just read
720 String name = tr.getTestName();
721 TestResult tr2 = tests.get(name);
722 if (tr2 != null) {
723 // cache also contains an entry for this test:
724 // reload from .jtr file in case of conflict
725 if (!tr2.getStatus().equals(tr.getStatus()))
726 tr = reload(tests, tr);
727 }
728 }
729 writeCacheEntry(tr);
730 debugCount++;
731 }
732 if (DEBUG_WORK && debugCount > 0)
733 Debug.println("TRC.writeCache write update (" + debugCount + " tests)");
734
735 raf.setLength(raf.getFilePointer());
736 lastFileSize = raf.length();
737 }
866 private WeakReference<WorkDirectory> weakWorkDir;
867 private File cacheFile;
868 private File lockFile;
869 private Thread worker;
870 private Thread shutdownHandler;
871
872 // worker thread data
873 private RandomAccessFile raf;
874 private int uniqueInitialEntryCount;
875 private int totalEntryCount;
876 private int lastSerial;
877 private long lastFileSize;
878 private boolean updateNeeded;
879
880 // synchronized data
881 private boolean fullUpdateRequested;
882 private boolean compressNeeded;
883 private boolean compressRequested;
884 private boolean flushRequested;
885 private boolean shutdownRequested;
886 private Fifo testsToWrite = new Fifo();
887
888 private static final String V1_FILENAME = "ResultCache.jtw";
889 private static final String V1_LOCKNAME = V1_FILENAME + ".lck";
890 private static final String V2_FILENAME = "ResultCache2.jtw";
891 private static final String V2_LOCKNAME = V2_FILENAME + ".lck";
892
893 // other
894 private static I18NResourceBundle i18n = I18NResourceBundle.getBundleForClass(TestResultCache.class);
895 private static int workerNumber; // for naming threads
896
897 // maximum length of reason string written into cache
898 // writeUTF can only write a limited length string, see writeCacheEntry()
899 private static final int MAX_REASON_LENGTH = 256;
900
901 private static int debug = Debug.getInt(TestResultCache.class);
902 private static final boolean DEBUG_BASIC = (debug >= 1); // basic messages and stack trace
903 private static final boolean DEBUG_TESTS = (debug >= 2); // details about tests
904 private static final boolean DEBUG_WORK = (debug >= 3); // details about work done
905 private static final boolean DEBUG_CHECK_WORK = (debug >= 4); // details when checking for work
906 private static final boolean DEBUG_SYNC = (debug >= 5); // details about thread syncs
|
659 tests.put(tr.getWorkRelativePath(), tr);
660 totalEntryCount++; // count all entries, including duplicates
661 }
662 lastFileSize = raf.length();
663 return tests;
664 }
665
666 //-------------------------------------------------------------------------------------
667 //
668 // Write the cache
669
670 private void writeCache(Map<String, TestResult> tests) throws IOException {
671 if (tests == null)
672 throw new IllegalStateException();
673
674 // merge any tests in testsToWrite
675 // testsToWrite is a thread-safe fifo, so it is safe to keep reading
676 // it till its empty, even though some tests may even have been added
677 // after the worker woke up
678 TestResult tr;
679 while ((tr = testsToWrite.remove()) != null) {
680 // check if test is in the set we've just read
681 String name = tr.getTestName();
682 TestResult tr2 = tests.get(name);
683 // if the cache file contains a conflicting entry,
684 // reload the test from the .jtr file; otherwise, add it to the cache
685 if (tr2 != null && !tr2.getStatus().equals(tr.getStatus()))
686 reload(tests, tr);
687 else
688 tests.put(tr.getWorkRelativePath(), tr);
689 }
690
691 // write cache
692 raf.seek(0);
693 long now = System.currentTimeMillis();
694 lastSerial = (int) ((now >> 16) + (now & 0xffff));
695 raf.writeInt(lastSerial);
696
697 for (Iterator<TestResult> iter = tests.values().iterator(); iter.hasNext(); ) {
698 tr = iter.next();
699 writeCacheEntry(tr);
700 }
701
702 if (DEBUG_WORK)
703 Debug.println("TRC.writeCache write all (" + tests.size() + " tests)");
704
705 raf.setLength(raf.getFilePointer());
706 lastFileSize = raf.length();
707 uniqueInitialEntryCount = totalEntryCount = tests.size();
708 }
709
710 private void updateCache(Map<String, TestResult> tests) throws IOException {
711 // testsToWrite is a thread-safe fifo, so it is safe to keep reading
712 // it till its empty, even though some tests may even have been added
713 // after the worker woke up
714 int debugCount = 0;
715 raf.seek(lastFileSize);
716 TestResult tr;
717 while ((tr = testsToWrite.remove()) != null) {
718 if (tests != null) {
719 // check if test is in the set we've just read
720 String name = tr.getTestName();
721 TestResult tr2 = tests.get(name);
722 if (tr2 != null) {
723 // cache also contains an entry for this test:
724 // reload from .jtr file in case of conflict
725 if (!tr2.getStatus().equals(tr.getStatus()))
726 tr = reload(tests, tr);
727 }
728 }
729 writeCacheEntry(tr);
730 debugCount++;
731 }
732 if (DEBUG_WORK && debugCount > 0)
733 Debug.println("TRC.writeCache write update (" + debugCount + " tests)");
734
735 raf.setLength(raf.getFilePointer());
736 lastFileSize = raf.length();
737 }
866 private WeakReference<WorkDirectory> weakWorkDir;
867 private File cacheFile;
868 private File lockFile;
869 private Thread worker;
870 private Thread shutdownHandler;
871
872 // worker thread data
873 private RandomAccessFile raf;
874 private int uniqueInitialEntryCount;
875 private int totalEntryCount;
876 private int lastSerial;
877 private long lastFileSize;
878 private boolean updateNeeded;
879
880 // synchronized data
881 private boolean fullUpdateRequested;
882 private boolean compressNeeded;
883 private boolean compressRequested;
884 private boolean flushRequested;
885 private boolean shutdownRequested;
886 private Fifo<TestResult> testsToWrite = new Fifo<>();
887
888 private static final String V1_FILENAME = "ResultCache.jtw";
889 private static final String V1_LOCKNAME = V1_FILENAME + ".lck";
890 private static final String V2_FILENAME = "ResultCache2.jtw";
891 private static final String V2_LOCKNAME = V2_FILENAME + ".lck";
892
893 // other
894 private static I18NResourceBundle i18n = I18NResourceBundle.getBundleForClass(TestResultCache.class);
895 private static int workerNumber; // for naming threads
896
897 // maximum length of reason string written into cache
898 // writeUTF can only write a limited length string, see writeCacheEntry()
899 private static final int MAX_REASON_LENGTH = 256;
900
901 private static int debug = Debug.getInt(TestResultCache.class);
902 private static final boolean DEBUG_BASIC = (debug >= 1); // basic messages and stack trace
903 private static final boolean DEBUG_TESTS = (debug >= 2); // details about tests
904 private static final boolean DEBUG_WORK = (debug >= 3); // details about work done
905 private static final boolean DEBUG_CHECK_WORK = (debug >= 4); // details when checking for work
906 private static final boolean DEBUG_SYNC = (debug >= 5); // details about thread syncs
|