AbstractSuspendable.java

1
package com.jsql.model.suspendable;
2
3
import com.jsql.model.InjectionModel;
4
import com.jsql.model.exception.JSqlException;
5
import com.jsql.util.LogLevelUtil;
6
import org.apache.logging.log4j.LogManager;
7
import org.apache.logging.log4j.Logger;
8
9
/**
10
 * A thread used to inject database ; stoppable and pausable.
11
 */
12
public abstract class AbstractSuspendable {
13
    
14
    /**
15
     * Log4j logger sent to view.
16
     */
17
    private static final Logger LOGGER = LogManager.getRootLogger();
18
19
    /**
20
     * Make the action to stop if true.
21
     */
22
    private boolean isStopped = false;
23
    
24
    /**
25
     * Make the action to pause if true, else make it unpause.
26
     */
27
    private boolean isPaused = false;
28
29
    protected final InjectionModel injectionModel;
30
    
31
    protected AbstractSuspendable(InjectionModel injectionModel) {
32
        this.injectionModel = injectionModel;
33
    }
34
    
35
    /**
36
     * The pausable/stoppable action.
37
     */
38
    public abstract String run(Object... args) throws JSqlException;
39
40
    /**
41
     * Thread's states Pause and Stop are processed by this method.<br>
42
     * - Pause action in infinite loop if invoked while shouldPauseThread is set to true,<br>
43
     * - Return stop state.
44
     * @return Stop state
45
     */
46
    public synchronized boolean isSuspended() {
47
        // Make application loop until shouldPauseThread is set to false by another user action
48 1 1. isSuspended : negated conditional → NO_COVERAGE
        while (this.isPaused) {
49
            try {
50 1 1. isSuspended : removed call to java/lang/Object::wait → NO_COVERAGE
                this.wait();
51
            } catch (InterruptedException e) {
52
                LOGGER.log(LogLevelUtil.IGNORE, e, e);
53 1 1. isSuspended : removed call to java/lang/Thread::interrupt → NO_COVERAGE
                Thread.currentThread().interrupt();
54
            }
55
        }
56 3 1. isSuspended : negated conditional → NO_COVERAGE
2. isSuspended : replaced boolean return with true for com/jsql/model/suspendable/AbstractSuspendable::isSuspended → NO_COVERAGE
3. isSuspended : negated conditional → NO_COVERAGE
        return this.isStopped || this.injectionModel.isStoppedByUser();  // Return true if stop requested, else return false
57
    }
58
    
59
    /**
60
     * Mark as stopped.
61
     */
62
    public void stop() {
63 1 1. stop : removed call to com/jsql/model/suspendable/AbstractSuspendable::unpause → NO_COVERAGE
        this.unpause();
64
        this.isStopped = true;
65
    }
66
    
67
    /**
68
     * Mark as paused.
69
     */
70
    public void pause() {
71
        this.isPaused = true;
72
    }
73
    
74
    /**
75
     * Mark as unpaused.
76
     */
77
    public void unpause() {
78
        this.isPaused = false;
79 1 1. unpause : removed call to com/jsql/model/suspendable/AbstractSuspendable::resume → NO_COVERAGE
        this.resume();  // Restart the action after unpause
80
    }
81
    
82
    /**
83
     * Return true if thread is paused, false otherwise.
84
     * @return Pause state
85
     */
86
    public boolean isPaused() {
87 2 1. isPaused : replaced boolean return with false for com/jsql/model/suspendable/AbstractSuspendable::isPaused → NO_COVERAGE
2. isPaused : replaced boolean return with true for com/jsql/model/suspendable/AbstractSuspendable::isPaused → NO_COVERAGE
        return this.isPaused;
88
    }
89
    
90
    /**
91
     * Wake threads.
92
     */
93
    public synchronized void resume() {
94 1 1. resume : removed call to java/lang/Object::notifyAll → NO_COVERAGE
        this.notifyAll();
95
    }
96
}

Mutations

48

1.1
Location : isSuspended
Killed by : none
negated conditional → NO_COVERAGE

50

1.1
Location : isSuspended
Killed by : none
removed call to java/lang/Object::wait → NO_COVERAGE

53

1.1
Location : isSuspended
Killed by : none
removed call to java/lang/Thread::interrupt → NO_COVERAGE

56

1.1
Location : isSuspended
Killed by : none
negated conditional → NO_COVERAGE

2.2
Location : isSuspended
Killed by : none
replaced boolean return with true for com/jsql/model/suspendable/AbstractSuspendable::isSuspended → NO_COVERAGE

3.3
Location : isSuspended
Killed by : none
negated conditional → NO_COVERAGE

63

1.1
Location : stop
Killed by : none
removed call to com/jsql/model/suspendable/AbstractSuspendable::unpause → NO_COVERAGE

79

1.1
Location : unpause
Killed by : none
removed call to com/jsql/model/suspendable/AbstractSuspendable::resume → NO_COVERAGE

87

1.1
Location : isPaused
Killed by : none
replaced boolean return with false for com/jsql/model/suspendable/AbstractSuspendable::isPaused → NO_COVERAGE

2.2
Location : isPaused
Killed by : none
replaced boolean return with true for com/jsql/model/suspendable/AbstractSuspendable::isPaused → NO_COVERAGE

94

1.1
Location : resume
Killed by : none
removed call to java/lang/Object::notifyAll → NO_COVERAGE

Active mutators

Tests examined


Report generated by PIT 1.19.1