resolve conflict in TestWriter
This commit is contained in:
commit
b55ba8410f
|
@ -177,4 +177,5 @@ public class TestWriter {
|
|||
return result;
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -9,21 +9,75 @@ import org.junit.Test;
|
|||
public class SandboxJavaTest {
|
||||
|
||||
@Test
|
||||
public void givenUsingTimer_whenSchedulingTaskOnce_thenCorrect() throws InterruptedException {
|
||||
final Timer timer = new Timer("Thread's name");
|
||||
System.out.println("Current time:" + new Date());
|
||||
System.out.println("Thread name: " + Thread.currentThread().getName());
|
||||
|
||||
public void givenUsingTimer_whenSchedulingTimerTaskOnce_thenCorrect() throws InterruptedException {
|
||||
final TimerTask timerTask = new TimerTask() {
|
||||
@Override
|
||||
public void run() {
|
||||
System.out.println("Time when task performed" + new Date());
|
||||
System.out.println("Thread name: " + Thread.currentThread().getName());
|
||||
timer.cancel();
|
||||
System.out.println("Time when was task performed" + new Date());
|
||||
System.out.println("Thread's name: " + Thread.currentThread().getName());
|
||||
}
|
||||
};
|
||||
final long delay = 2 * 1000;
|
||||
final Timer timer = new Timer("Thread's name");
|
||||
System.out.println("Current time:" + new Date());
|
||||
System.out.println("Thread's name: " + Thread.currentThread().getName());
|
||||
final long delay = 2L * 1000L;
|
||||
timer.schedule(timerTask, delay);
|
||||
Thread.sleep(delay);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenUsingTimer_whenSchedulingRepeatedTask_thenCorrect() throws InterruptedException {
|
||||
final TimerTask repeatedTask = new TimerTask() {
|
||||
int count = 0;
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
count++;
|
||||
System.out.println("Time when task was performed: " + new Date());
|
||||
System.out.println("Thread's name: " + Thread.currentThread().getName());
|
||||
if (count >= 5) {
|
||||
cancel();
|
||||
}
|
||||
}
|
||||
};
|
||||
final Timer timer = new Timer("Timer thread");
|
||||
System.out.println("Current time: " + new Date());
|
||||
System.out.println("Thread's name: " + Thread.currentThread().getName());
|
||||
final long delay = 2L * 1000L;
|
||||
final long period = 1L * 1000L;
|
||||
timer.scheduleAtFixedRate(repeatedTask, delay, period);
|
||||
Thread.sleep(delay + period * 5L);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenUsingTimer_whenSchedulingRepeatedCustomTimerTask_thenCorrect() throws InterruptedException {
|
||||
class MyTask extends TimerTask {
|
||||
long timesToRun = 0;
|
||||
long timesRunned = 0;
|
||||
|
||||
public void setTimesToRun(final int timesToRun) {
|
||||
this.timesToRun = timesToRun;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
timesRunned++;
|
||||
System.out.println("Task performed on: " + new Date());
|
||||
System.out.println("Thread's name: " + Thread.currentThread().getName());
|
||||
if (timesRunned >= timesToRun) {
|
||||
cancel();
|
||||
}
|
||||
}
|
||||
}
|
||||
final MyTask repeatedTask = new MyTask();
|
||||
repeatedTask.setTimesToRun(5);
|
||||
final long delay = 2L * 1000L;
|
||||
final long period = 1L * 1000L;
|
||||
final Timer timer = new Timer("Timer");
|
||||
System.out.println("Current time: " + new Date());
|
||||
System.out.println("Thread's name: " + Thread.currentThread().getName());
|
||||
timer.scheduleAtFixedRate(repeatedTask, delay, period);
|
||||
Thread.sleep(delay + period * repeatedTask.timesToRun);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
################### DataSource Configuration ##########################
|
||||
jdbc.driverClassName=com.mysql.jdbc.Driver
|
||||
jdbc.url=jdbc:mysql://localhost:3306/AUTHDATA
|
||||
jdbc.url=jdbc:mysql://localhost:3306/authdata?createDatabaseIfNotExist=true
|
||||
jdbc.user=tutorialuser
|
||||
jdbc.pass=tutorialmy5ql
|
||||
init-db=false
|
||||
################### Hibernate Configuration ##########################
|
||||
hibernate.dialect=org.hibernate.dialect.MySQLDialect
|
||||
hibernate.show_sql=true
|
||||
hibernate.hbm2ddl.auto=validate
|
||||
hibernate.hbm2ddl.auto=create-drop
|
||||
|
|
Loading…
Reference in New Issue