resolve conflict in TestWriter
This commit is contained in:
commit
b55ba8410f
|
@ -177,4 +177,5 @@ public class TestWriter {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
|
@ -9,21 +9,75 @@ import org.junit.Test;
|
||||||
public class SandboxJavaTest {
|
public class SandboxJavaTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void givenUsingTimer_whenSchedulingTaskOnce_thenCorrect() throws InterruptedException {
|
public void givenUsingTimer_whenSchedulingTimerTaskOnce_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());
|
|
||||||
|
|
||||||
final TimerTask timerTask = new TimerTask() {
|
final TimerTask timerTask = new TimerTask() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
System.out.println("Time when task performed" + new Date());
|
System.out.println("Time when was task performed" + new Date());
|
||||||
System.out.println("Thread name: " + Thread.currentThread().getName());
|
System.out.println("Thread's name: " + Thread.currentThread().getName());
|
||||||
timer.cancel();
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
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);
|
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 ##########################
|
################### DataSource Configuration ##########################
|
||||||
jdbc.driverClassName=com.mysql.jdbc.Driver
|
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.user=tutorialuser
|
||||||
jdbc.pass=tutorialmy5ql
|
jdbc.pass=tutorialmy5ql
|
||||||
init-db=false
|
init-db=false
|
||||||
################### Hibernate Configuration ##########################
|
################### Hibernate Configuration ##########################
|
||||||
hibernate.dialect=org.hibernate.dialect.MySQLDialect
|
hibernate.dialect=org.hibernate.dialect.MySQLDialect
|
||||||
hibernate.show_sql=true
|
hibernate.show_sql=true
|
||||||
hibernate.hbm2ddl.auto=validate
|
hibernate.hbm2ddl.auto=create-drop
|
||||||
|
|
Loading…
Reference in New Issue