java - Spring boot integration test Watch Service Struggles -


hi having couple of issues in writing integration test spring boot service uses java watch service.

first off require spring bean run on start up, have implemented applicationrunner interface. set watch service poll events take() method. blocks until event received. issue have no matter in integration test, test never getting executed, seems block on watcher.take() method

@component public class myclass implements applicationrunner {  private static boolean shutdown;  private watchservice watcher;  @value("${file.location}") private string filelocation;  @override public void run(applicationarguments args) {      path mydir = paths.get(filelocation);      try {         watcher = mydir.getfilesystem().newwatchservice();         mydir.register(watcher, standardwatcheventkinds.entry_create);         while(true) {             watchkey watchkey = watcher.take();             list<watchevent<?>> events = watchkey.pollevents();             (watchevent event : events) {                 if (event.kind() == standardwatcheventkinds.entry_create) {                     //dosomething                 }             }              watchkey.reset();         }     } 

}

my integration test class below never seems execute first line of test? goes run method of main class. possible change value of filelocation injected value in integration test?

@runwith(springrunner.class) @springboottest public class testit {   @test public void testfilegetspickedupandprocessed() throws ioexception, interruptedexception{      classloader classloader = getclass().getclassloader();     file file = new file(classloader.getresource("pickme.txt").getfile());      file.renameto(new file("/tmp/pickme.txt"));     //some assertions  } 


Comments

Popular posts from this blog

Is there a better way to structure post methods in Class Based Views -

performance - Why is XCHG reg, reg a 3 micro-op instruction on modern Intel architectures? -

jquery - Responsive Navbar with Sub Navbar -