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

Mutations

38

1.1
Location : run
Killed by : none
replaced return value with "" for com/jsql/model/suspendable/AbstractSuspendable::run → NO_COVERAGE

49

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

51

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

54

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

57

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

64

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

80

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

88

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

95

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.22.1