270. EPMO Open Source Coordination Office Redaction File Detail Report

Produced by Araxis Merge on 2/4/2019 11:34:04 AM Eastern Standard Time. See www.araxis.com for information about Merge. This report uses XHTML and CSS2, and is best viewed with a modern standards-compliant browser. For optimum results when printing this report, use landscape orientation and enable printing of background images and colours in your browser.

270.1 Files compared

# Location File Last Modified
1 MHPRO_v1.x.zip\mhpro-resources-master@a26412b610c.zip\ws\src\test\java\gov\va\mobile\vamf\mhpro\datalayer\impl QuartzSemaphoreRepositoryImplTest.java Tue Nov 14 19:31:17 2017 UTC
2 MHPRO_v1.x.zip\mhpro-resources-master@a26412b610c.zip\ws\src\test\java\gov\va\mobile\vamf\mhpro\datalayer\impl QuartzSemaphoreRepositoryImplTest.java Mon Feb 4 15:13:47 2019 UTC

270.2 Comparison summary

Description Between
Files 1 and 2
Text Blocks Lines
Unchanged 2 318
Changed 1 2
Inserted 0 0
Removed 0 0

270.3 Comparison options

Whitespace
Character case Differences in character case are significant
Line endings Differences in line endings (CR and LF characters) are ignored
CR/LF characters Not shown in the comparison detail

270.4 Active regular expressions

No regular expressions were active.

270.5 Comparison detail

  1   package go v.va.mobil e.vamf.mhp ro.datalay er.impl;
  2  
  3   import jav a.util.Arr ayList;
  4   import jav a.util.Lis t;
  5   import jav a.util.con current.Ca llable;
  6   import jav a.util.con current.Ex ecutionExc eption;
  7   import jav a.util.con current.Ex ecutorServ ice;
  8   import jav a.util.con current.Ex ecutors;
  9   import jav a.util.con current.Fu ture;
  10  
  11   import org .junit.Ass ert;
  12   import org .junit.Tes t;
  13   import org .junit.run ner.RunWit h;
  14   import org .springfra mework.bea ns.factory .annotatio n.Autowire d;
  15   import org .springfra mework.dat a.mongodb. core.Mongo Template;
  16   import org .springfra mework.dat a.mongodb. core.query .Criteria;
  17   import org .springfra mework.dat a.mongodb. core.query .Query;
  18   import org .springfra mework.tes t.context. ContextCon figuration ;
  19   import org .springfra mework.tes t.context. junit4.Spr ingJUnit4C lassRunner ;
  20   import org .springfra mework.tes t.context. web.WebApp Configurat ion;
  21  
  22   import gov .va.mobile .vamf.mhpr o.datalaye r.impl.Qua rtzSemapho reReposito ryImpl.Pid Generator;
  23   import gov .va.mobile .vamf.mhpr o.domain.J obType;
  24   import gov .va.mobile .vamf.mhpr o.domain.Q uartzSemap hore;
  25   import gov .va.mobile .vamf.mhpr o.domain.Q uartzSemap horeLock;
  26  
  27   /**
  28    * 
  29    * @author   PII
  30    *
  31    */
  32   @RunWith(S pringJUnit 4ClassRunn er.class)
  33   @WebAppCon figuration
  34   @ContextCo nfiguratio n({ "class path:appli cationCont ext.xml",  "classpath :dispatche r-servlet. xml",
  35                    "cla sspath:mon goContext. xml" })
  36   public cla ss QuartzS emaphoreRe positoryIm plTest {
  37           
  38           st atic final  int RUN_S ECONDS = 1 5;
  39           
  40           in t threads  = 3;
  41           in t threadIn dexWithLoc k = -1;
  42           lo ng endTime Millis;
  43  
  44           @A utowired
  45           Qu artzSemaph oreReposit oryImpl re pository;
  46           @A utowired
  47           Mo ngoTemplat e mongoTem plate;
  48  
  49           Ob ject local Lock = new  Object();
  50  
  51           //  @Test
  52           pu blic void  testSaveSe maphore()  {
  53                    mong oTemplate. remove(new  Query(Cri teria.wher e("_id").i s(String.v alueOf(Job Type.UNIT_ TEST_JOB.g etCode())) ),
  54                                      QuartzSe maphore.cl ass);
  55  
  56                    Quar tzSemaphor eLock lock  = reposit ory.tryLoc k(JobType. UNIT_TEST_ JOB, 1800) ;
  57                    Asse rt.assertT rue(lock ! = null);
  58                    Quar tzSemaphor eLock lock 2 = reposi tory.tryLo ck(JobType .UNIT_TEST _JOB, 1800 );
  59                    Asse rt.assertT rue(lock2  == null);
  60                    bool ean unlock Successful  = reposit ory.unlock (lock);
  61                    Asse rt.assertT rue(unlock Successful );
  62           }
  63  
  64           @T est
  65           pu blic void  testCreate Duplicates () throws  Interrupte dException , Executio nException  {
  66                    mong oTemplate. remove(new  Query(Cri teria.wher e("_id").i s(String.v alueOf(Job Type.UNIT_ TEST_JOB.g etCode())) ),
  67                                      QuartzSe maphore.cl ass);
  68  
  69                    logA ndTime("St arting tes t with " +  threads +  " threads ...");
  70                    List <Callable< Exception> > calls =  new ArrayL ist<>();
  71  
  72                    for  (int i = 0 ; i < thre ads; i++)  {
  73                             final  int i2 = i ;
  74  
  75                             calls. add(new Ca llable<Exc eption>()  {
  76                                      @Overrid e
  77                                      public E xception c all() {
  78                                               PidGenerat or generat or = new P idGenerato r() {
  79                                                       @O verride
  80                                                       pu blic Strin g getPid()  {
  81                                                                retu rn i2 + "@ testServer ";
  82                                                       }
  83                                               };
  84  
  85                                               try {
  86                                                       bo olean prin tedRejecte d = false;
  87  
  88                                                       wh ile (Syste m.currentT imeMillis( ) < endTim eMillis) {
  89                                                                Quar tzSemaphor eLock lock  = reposit ory.tryLoc kInternal( JobType.UN IT_TEST_JO B, 1800,
  90                                                                                  generato r);
  91                                                                if ( lock != nu ll) {
  92                                                                         setLoc k(i2, true );
  93                                                                         logAnd Time("Esta blished lo ck");
  94  
  95                                                                         boolea n successf ul = repos itory.unlo ckInternal (lock, gen erator);
  96                                                                         if (su ccessful)  {
  97                                                                                  setLock( i2, false) ;
  98                                                                                  logAndTi me("Unlock ed");
  99                                                                         } else  {
  100                                                                                  System.o ut.println ("Couldn't  unlock "  + lock);
  101                                                                         }
  102                                                                         printe dRejected  = false;
  103                                                                } el se {
  104                                                                         if (!p rintedReje cted) {
  105                                                                                  logAndTi me("Reject ed!");
  106                                                                                  printedR ejected =  true;
  107                                                                         }
  108                                                                }
  109                                                       }
  110                                                       re turn null;
  111                                               } catch (E xception e ) {
  112                                                       re turn e;
  113                                               }
  114                                      }
  115                             });
  116                    }
  117  
  118                    endT imeMillis  = System.c urrentTime Millis() +  RUN_SECON DS * 1000;
  119                    Exec utorServic e threadPo ol = Execu tors.newFi xedThreadP ool(thread s);
  120                    List <Future<Ex ception>>  futures =  new ArrayL ist<>();
  121                    for  (Callable< Exception>  b : calls )
  122                             future s.add(thre adPool.sub mit(b));
  123                    for  (Future<Ex ception> f  : futures ) {
  124                             Except ion b = f. get();
  125                             if (b  != null) {
  126                                      endTimeM illis = 0;
  127                                      delay(50 00);
  128                                      Assert.f ail(b.getM essage());
  129                             }
  130                    }
  131           }
  132  
  133           pr ivate void  logAndTim e(String s ) {
  134                    sync hronized ( localLock)  {
  135                             System .out.print ("[");
  136                             System .out.print (threadInd exWithLock  != -1 ? S tring.valu eOf(thread IndexWithL ock) : " " );
  137                             System .out.print ln(
  138                                               "] ; " + ( System.cur rentTimeMi llis() / 1 000) + " -  " + Threa d.currentT hread().ge tId() + ":  " + s);
  139                    }
  140           }
  141  
  142           pr ivate void  setLock(i nt index,  boolean va l) {
  143                    sync hronized ( localLock)  {
  144                             if (va l && threa dIndexWith Lock != -1  && thread IndexWithL ock != ind ex)
  145                                      throw ne w RuntimeE xception(
  146                                                       in dex + " tr ied to che ck out but  was alrea dy checked  out to "  + threadIn dexWithLoc k);
  147                             logAnd Time("upda ting threa dIndexWith Lock to "  + (val ? i ndex : "-1 "));
  148                             thread IndexWithL ock = val  ? index :  -1;
  149                    }
  150           }
  151  
  152           pr ivate void  delay(lon g millis)  {
  153                    try  {
  154                             Thread .sleep(mil lis);
  155                    } ca tch (Inter ruptedExce ption e) {
  156                             e.prin tStackTrac e();
  157                    }
  158           }
  159  
  160   }