EMMA Coverage Report (generated Thu May 22 12:08:10 CDT 2014)
[all classes][org.springframework.batch.repeat.policy]

COVERAGE SUMMARY FOR SOURCE FILE [SimpleCompletionPolicy.java]

nameclass, %method, %block, %line, %
SimpleCompletionPolicy.java100% (2/2)91%  (10/11)83%  (64/77)95%  (19/20)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class SimpleCompletionPolicy100% (1/1)88%  (7/8)77%  (44/57)93%  (13/14)
toString (): String 0%   (0/1)0%   (0/13)0%   (0/1)
SimpleCompletionPolicy (): void 100% (1/1)100% (4/4)100% (2/2)
SimpleCompletionPolicy (int): void 100% (1/1)100% (9/9)100% (4/4)
isComplete (RepeatContext): boolean 100% (1/1)100% (4/4)100% (1/1)
isComplete (RepeatContext, RepeatStatus): boolean 100% (1/1)100% (13/13)100% (1/1)
setChunkSize (int): void 100% (1/1)100% (4/4)100% (2/2)
start (RepeatContext): RepeatContext 100% (1/1)100% (6/6)100% (1/1)
update (RepeatContext): void 100% (1/1)100% (4/4)100% (2/2)
     
class SimpleCompletionPolicy$SimpleTerminationContext100% (1/1)100% (3/3)100% (20/20)100% (6/6)
SimpleCompletionPolicy$SimpleTerminationContext (SimpleCompletionPolicy, Repe... 100% (1/1)100% (7/7)100% (3/3)
isComplete (): boolean 100% (1/1)100% (10/10)100% (1/1)
update (): void 100% (1/1)100% (3/3)100% (2/2)

1/*
2 * Copyright 2006-2007 the original author or authors.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *      http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16 
17package org.springframework.batch.repeat.policy;
18 
19import org.springframework.batch.repeat.RepeatStatus;
20import org.springframework.batch.repeat.RepeatContext;
21import org.springframework.batch.repeat.context.RepeatContextSupport;
22import org.springframework.batch.repeat.support.RepeatTemplate;
23import org.springframework.util.ClassUtils;
24 
25/**
26 * Policy for terminating a batch after a fixed number of operations. Internal
27 * state is maintained and a counter incremented, so successful use of this
28 * policy requires that isComplete() is only called once per batch item. Using
29 * the standard {@link RepeatTemplate} should ensure this contract is kept, but it needs
30 * to be carefully monitored.
31 * 
32 * @author Dave Syer
33 * 
34 */
35public class SimpleCompletionPolicy extends DefaultResultCompletionPolicy {
36 
37        public static final int DEFAULT_CHUNK_SIZE = 5;
38 
39        int chunkSize = 0;
40 
41        public SimpleCompletionPolicy() {
42                this(DEFAULT_CHUNK_SIZE);
43        }
44 
45        public SimpleCompletionPolicy(int chunkSize) {
46                super();
47                this.chunkSize = chunkSize;
48        }
49 
50        public void setChunkSize(int chunkSize) {
51                this.chunkSize = chunkSize;
52        }
53 
54        /**
55         * Reset the counter.
56         * 
57         * @see org.springframework.batch.repeat.CompletionPolicy#start(RepeatContext)
58         */
59    @Override
60        public RepeatContext start(RepeatContext context) {
61                return new SimpleTerminationContext(context);
62        }
63 
64        /**
65         * Terminate if the chunk size has been reached, or the result is null.
66         * 
67         * @see org.springframework.batch.repeat.CompletionPolicy#isComplete(RepeatContext,
68         * RepeatStatus)
69         * @throws RuntimeException (normally terminating the batch) if the result is
70         * itself an exception.
71         */
72    @Override
73        public boolean isComplete(RepeatContext context, RepeatStatus result) {
74                return super.isComplete(context, result) || ((SimpleTerminationContext) context).isComplete();
75        }
76 
77        /**
78         * Terminate if the chunk size has been reached.
79         * 
80         * @see org.springframework.batch.repeat.CompletionPolicy#isComplete(RepeatContext)
81         */
82    @Override
83        public boolean isComplete(RepeatContext context) {
84                return ((SimpleTerminationContext) context).isComplete();
85        }
86 
87        /**
88         * Increment the counter in the context.
89         * 
90         * @see org.springframework.batch.repeat.CompletionPolicy#update(RepeatContext)
91         */
92    @Override
93        public void update(RepeatContext context) {
94                ((SimpleTerminationContext) context).update();
95        }
96 
97        protected class SimpleTerminationContext extends RepeatContextSupport {
98 
99                public SimpleTerminationContext(RepeatContext context) {
100                        super(context);
101                }
102 
103                public void update() {
104                        increment();
105                }
106 
107                public boolean isComplete() {
108                        return getStartedCount() >= chunkSize;
109                }
110        }
111        
112        /* (non-Javadoc)
113         * @see java.lang.Object#toString()
114         */
115    @Override
116        public String toString() {
117                return ClassUtils.getShortName(SimpleCompletionPolicy.class)+": chunkSize="+chunkSize;
118        }
119 
120}

[all classes][org.springframework.batch.repeat.policy]
EMMA 2.0.5312 (C) Vladimir Roubtsov