本文整理汇总了Java中javax.batch.runtime.StepExecution.getMetrics方法的典型用法代码示例。如果您正苦于以下问题:Java StepExecution.getMetrics方法的具体用法?Java StepExecution.getMetrics怎么用?Java StepExecution.getMetrics使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.batch.runtime.StepExecution
的用法示例。
在下文中一共展示了StepExecution.getMetrics方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: checkpointAlgorithm
import javax.batch.runtime.StepExecution; //导入方法依赖的package包/类
@Test
public void checkpointAlgorithm() throws Exception {
logger.info("starting checkpoint test");
CountDownLatch latch = new CountDownLatch(1);
JobOperator jobOperator = getJobOperator();
Properties props = new Properties();
long executionId = jobOperator.start(JOB_NAME, props);
latch.await(10, SECONDS);
JobInstance jobInstance = jobInstance(jobOperator.getJobInstance(executionId), JOB_NAME);
JobExecution jobExecution = jobOperator.getJobExecutions(jobInstance).get(0);
Properties jobProperties = jobExecution.getJobParameters();
assertEquals("properties are: ", 0, jobProperties.size());
assertEquals("batch failed because a NoRollbackException is throwed", FAILED, jobExecution.getBatchStatus());
StepExecution stepExecution = jobOperator.getStepExecutions(executionId).get(0);
PersistentCheckpointUserData persistentCheckpointUserData = (PersistentCheckpointUserData) stepExecution
.getPersistentUserData();
assertNull("persistent user data after step", persistentCheckpointUserData.getStartedAfterStep());
Metric[] stepMetrics = stepExecution.getMetrics();
stepMetrics(stepMetrics, 3, 10, 12, 2, 1);
}
开发者ID:PacktPublishing,项目名称:Mastering-Java-EE-Development-with-WildFly,代码行数:22,代码来源:CheckpointJobTestCase.java
示例2: showStepState
import javax.batch.runtime.StepExecution; //导入方法依赖的package包/类
private void showStepState(StepExecution step) {
Reporter.log("---------------------------<p>");
Reporter.log("getStepName(): " + step.getStepName() + " - ");
Reporter.log("getStepExecutionId(): " + step.getStepExecutionId() + " - ");
Metric[] metrics = step.getMetrics();
for (int i = 0; i < metrics.length; i++) {
Reporter.log(metrics[i].getType() + ": " + metrics[i].getValue() + " - ");
}
Reporter.log("getStartTime(): " + step.getStartTime() + " - ");
Reporter.log("getEndTime(): " + step.getEndTime() + " - ");
Reporter.log("getBatchStatus(): " + step.getBatchStatus() + " - ");
Reporter.log("getExitStatus(): " + step.getExitStatus()+"<p>");
Reporter.log("---------------------------<p>");
}
示例3: showStepState
import javax.batch.runtime.StepExecution; //导入方法依赖的package包/类
private void showStepState(StepExecution step) {
Reporter.log("---------------------------<p>");
Reporter.log("getJobExecutionId(): " + step.getStepExecutionId() + " - ");
Metric[] metrics = step.getMetrics();
for (int i = 0; i < metrics.length; i++) {
Reporter.log(metrics[i].getType() + ": " + metrics[i].getValue() + " - ");
}
Reporter.log("getStartTime(): " + step.getStartTime() + " - ");
Reporter.log("getEndTime(): " + step.getEndTime() + " - ");
Reporter.log("getBatchStatus(): " + step.getBatchStatus() + " - ");
Reporter.log("getExitStatus(): " + step.getExitStatus());
Reporter.log("---------------------------<p>");
}
示例4: showStepState
import javax.batch.runtime.StepExecution; //导入方法依赖的package包/类
private void showStepState(StepExecution step) {
Reporter.log("---------------------------");
Reporter.log("getStepName(): " + step.getStepName() + " - ");
Reporter.log("getJobExecutionId(): " + step.getStepExecutionId() + " - ");
//System.out.print("getStepExecutionId(): " + step.getStepExecutionId() + " - ");
Metric[] metrics = step.getMetrics();
for (int i = 0; i < metrics.length; i++) {
Reporter.log(metrics[i].getType() + ": " + metrics[i].getValue() + " - ");
}
Reporter.log("getStartTime(): " + step.getStartTime() + " - ");
Reporter.log("getEndTime(): " + step.getEndTime() + " - ");
//System.out.print("getLastUpdateTime(): " + step.getLastUpdateTime() + " - ");
Reporter.log("getBatchStatus(): " + step.getBatchStatus() + " - ");
Reporter.log("getExitStatus(): " + step.getExitStatus());
Reporter.log("---------------------------");
}
示例5: testRolledBackDuringWork
import javax.batch.runtime.StepExecution; //导入方法依赖的package包/类
@Test
public void testRolledBackDuringWork() {
final JobOperator jobOperator = BatchRuntime.getJobOperator();
long executionId = jobOperator.start("txtest1", null);
BatchStatus batchStatus = Batches.waitFor(jobOperator, executionId);
Assert.assertEquals(batchStatus, BatchStatus.FAILED);
Assert.assertEquals(TxErrorWriter1.written.intValue(), 3);
List<StepExecution> stepExecutions = jobOperator.getStepExecutions(executionId);
Assert.assertEquals(stepExecutions.size(), 1);
StepExecution stepExecution = stepExecutions.get(0);
Metric[] metrics = stepExecution.getMetrics();
assertMetric(Metric.MetricType.READ_COUNT, 2, metrics);
assertMetric(Metric.MetricType.WRITE_COUNT, 2, metrics);
assertMetric(Metric.MetricType.ROLLBACK_COUNT, 1, metrics);
}
示例6: run
import javax.batch.runtime.StepExecution; //导入方法依赖的package包/类
@Test
public void run() {
final JobOperator op = BatchRuntime.getJobOperator();
final long id = op.start("partition-metrics", null);
Batches.waitForEnd(op, id);
final List<StepExecution> steps = op.getStepExecutions(id);
assertEquals(1, steps.size());
final StepExecution exec = steps.iterator().next();
final Metric[] metrics = exec.getMetrics();
int checked = 0;
for (final Metric metric : metrics) {
if (Metric.MetricType.ROLLBACK_COUNT == metric.getType()) {
assertEquals(metric.getValue(), 1);
checked++;
} else if (Metric.MetricType.READ_SKIP_COUNT == metric.getType()) {
assertEquals(metric.getValue(), 1);
checked++;
}
}
assertEquals(checked, 2);
}
示例7: execute
import javax.batch.runtime.StepExecution; //导入方法依赖的package包/类
@Override
public void execute() throws MojoExecutionException, MojoFailureException {
final List<StepExecution> executions = getOrCreateOperator().getStepExecutions(executionId);
getLog().info("Step executions for job execution #" + executionId + ":");
for (final StepExecution exec : executions) {
getLog().info(" - id = " + exec.getStepExecutionId());
getLog().info(" + step = " + exec.getStepName());
getLog().info(" + batch status = " + exec.getBatchStatus());
getLog().info(" + exit status = " + exec.getExitStatus());
getLog().info(" + start time = " + exec.getStartTime());
getLog().info(" + end time = " + exec.getEndTime());
getLog().info(" + metrics");
if (exec.getMetrics() != null) {
for (final Metric m : exec.getMetrics()) {
getLog().info(" > " + m.getType().name().replace("COUNT", "").replace("_", " ").toLowerCase(Locale.ENGLISH) + " = " + m.getValue());
}
}
}
}
示例8: testPartitionedRollbackMetric
import javax.batch.runtime.StepExecution; //导入方法依赖的package包/类
@Test
public void testPartitionedRollbackMetric() throws Exception {
Properties origParams = new Properties();
// These two don't matter
origParams.setProperty("step1Size", "15"); origParams.setProperty("step2Size", "20");
origParams.setProperty("chunkListener.forceFailure", "true");
long execId = jobOp.start("partitionMetrics", origParams);
Thread.sleep(sleepTime);
assertEquals("Didn't fail as expected successfully", BatchStatus.FAILED, jobOp.getJobExecution(execId).getBatchStatus());
StepExecution step1Exec = null; StepExecution step2Exec = null;
for (StepExecution se : jobOp.getStepExecutions(execId)) {
if (se.getStepName().equals("step1")) {
step1Exec = se;
} else if (se.getStepName().equals("step2")) {
step2Exec = se;
}
}
Metric[] metrics = step1Exec.getMetrics();
// 3 partitions - this confirms that the read, filter, write counts get rolled back
assertEquals("commit count", 0, getMetricVal(metrics, Metric.MetricType.COMMIT_COUNT));
assertEquals("filter count", 0, getMetricVal(metrics, Metric.MetricType.FILTER_COUNT));
assertEquals("read count", 0, getMetricVal(metrics, Metric.MetricType.READ_COUNT));
assertEquals("write count", 0, getMetricVal(metrics, Metric.MetricType.WRITE_COUNT));
assertEquals("rollback count", 3, getMetricVal(metrics, Metric.MetricType.ROLLBACK_COUNT));
}
示例9: validatePartitionedMetrics
import javax.batch.runtime.StepExecution; //导入方法依赖的package包/类
private void validatePartitionedMetrics(String jslName) throws Exception {
Properties origParams = new Properties();
origParams.setProperty("step1Size", "15");
origParams.setProperty("step2Size", "20");
long execId = jobOp.start(jslName, origParams);
Thread.sleep(sleepTime);
assertEquals("Didn't complete successfully", BatchStatus.COMPLETED, jobOp.getJobExecution(execId).getBatchStatus());
StepExecution step1Exec = null; StepExecution step2Exec = null;
for (StepExecution se : jobOp.getStepExecutions(execId)) {
if (se.getStepName().equals("step1")) {
step1Exec = se;
} else if (se.getStepName().equals("step2")) {
step2Exec = se;
}
}
Metric[] metrics = step1Exec.getMetrics();
// 3 partitions of 15 elements - for each partition, 9 will be written and 6 will be filtered, this will be 3 chunks (item-count=5) + 1 zero-item chunk
assertEquals("commit count", 12, getMetricVal(metrics, Metric.MetricType.COMMIT_COUNT));
assertEquals("filter count", 18, getMetricVal(metrics, Metric.MetricType.FILTER_COUNT));
assertEquals("read count", 45, getMetricVal(metrics, Metric.MetricType.READ_COUNT));
assertEquals("write count", 27, getMetricVal(metrics, Metric.MetricType.WRITE_COUNT));
Metric[] metrics2 = step2Exec.getMetrics();
// 3 partitions of 20 elements - for each partition, 12 will be written and 8 will be filtered, this will be 4 chunks (item-count=5) + 1 zero-item chunk
assertEquals("commit count", 15, getMetricVal(metrics2, Metric.MetricType.COMMIT_COUNT));
assertEquals("filter count", 24, getMetricVal(metrics2, Metric.MetricType.FILTER_COUNT));
assertEquals("read count", 60, getMetricVal(metrics2, Metric.MetricType.READ_COUNT));
assertEquals("write count", 36, getMetricVal(metrics2, Metric.MetricType.WRITE_COUNT));
}
示例10: reportMetricsCsv
import javax.batch.runtime.StepExecution; //导入方法依赖的package包/类
private void reportMetricsCsv(HttpServletResponse resp, List<StepExecution> stepExecutions) {
StringBuilder stringBuilder = new StringBuilder(200);
stringBuilder.append("\n");
// append csv header to stringbuilder
joinCsv(stringBuilder, Arrays.asList("STEP_EXECUTION_ID", "STEP_NAME"));
stringBuilder.append(CSV_DELIMITER);
joinCsv(stringBuilder, Arrays.asList(Metric.MetricType.values()));
stringBuilder.append("\n");
Collections.sort(stepExecutions, new Comparator<StepExecution>() {
@Override
public int compare(StepExecution o1, StepExecution o2) {
return Long.compare(o1.getStepExecutionId(), o2.getStepExecutionId());
}
});
// append csv values to stringbuilder, one stepExecution per line
for (StepExecution stepExecution : stepExecutions) {
stringBuilder.append(stepExecution.getStepExecutionId());
stringBuilder.append(CSV_DELIMITER);
stringBuilder.append(stepExecution.getStepName());
stringBuilder.append(CSV_DELIMITER);
Metric[] metricsArray = stepExecution.getMetrics();
Map<Metric.MetricType, Metric> sourceMap = new HashMap<Metric.MetricType, Metric>();
for (Metric metric : metricsArray) {
sourceMap.put(metric.getType(), metric);
}
List<String> orderedMetricsValues = new ArrayList<String>();
for (Metric.MetricType type : Metric.MetricType.values()) {
orderedMetricsValues.add(sourceMap.containsKey(type) ? String.valueOf(sourceMap.get(type).getValue()) : NOT_FOUND_STRING);
}
joinCsv(stringBuilder, orderedMetricsValues);
stringBuilder.append("\n");
}
writeContent(resp, stringBuilder.toString());
}
示例11: wrap
import javax.batch.runtime.StepExecution; //导入方法依赖的package包/类
private static RestStepExecution wrap(final StepExecution exec) {
final RestStepExecution execution = new RestStepExecution();
execution.setId(exec.getStepExecutionId());
execution.setName(exec.getStepName());
execution.setBatchStatus(exec.getBatchStatus());
execution.setExitStatus(exec.getExitStatus());
execution.setStartTime(exec.getStartTime());
execution.setEndTime(exec.getEndTime());
if (exec.getMetrics() != null) {
for (final Metric m : exec.getMetrics()) {
execution.getMetrics().add(RestMetric.wrap(m));
}
}
return execution;
}
示例12: testMetricsSkipRead
import javax.batch.runtime.StepExecution; //导入方法依赖的package包/类
@Test
@org.junit.Test
public void testMetricsSkipRead() throws Exception {
String METHOD = "testMetricsSkipRead";
try {
Reporter.log("Create job parameters for execution #1:<p>");
Properties jobParams = new Properties();
Reporter.log("execution.number=1<p>");
Reporter.log("readrecord.fail=1,3<p>");
Reporter.log("app.arraysize=30<p>");
Reporter.log("numberOfSkips=2<p>");
Reporter.log("ReadProcessWrite=READ_SKIP<p>");
jobParams.put("execution.number", "1");
jobParams.put("readrecord.fail", "1,3,4,12");
jobParams.put("app.arraysize", "30");
jobParams.put("numberOfSkips", "4");
jobParams.put("ReadProcessWrite", "READ_SKIP");
Reporter.log("Locate job XML file: testMetricsSkipCount.xml<p>");
Reporter.log("Invoke startJobAndWaitForResult for execution #1<p>");
JobExecution execution1 = jobOp.startJobAndWaitForResult("testMetricsSkipCount",
jobParams);
Reporter.log("execution #1 JobExecution getBatchStatus()="
+ execution1.getBatchStatus() + "<p>");
Reporter.log("execution #1 JobExecution getExitStatus()="
+ execution1.getExitStatus() + "<p>");
assertWithMessage("Testing execution #1", BatchStatus.COMPLETED,
execution1.getBatchStatus());
assertWithMessage("Testing execution #1",
MetricsStepListener.GOOD_EXIT_STATUS_READ,
execution1.getExitStatus());
List<StepExecution> stepExecutions = jobOp
.getStepExecutions(execution1.getExecutionId());
StepExecution step = null;
String stepNameTest = "step1";
for (StepExecution stepEx : stepExecutions) {
if (stepNameTest.equals(stepEx.getStepName())) {
step = stepEx;
}
}
Reporter.log("execution #1 JobExecution getBatchStatus()="
+ execution1.getBatchStatus() + "<p>");
assertWithMessage("Testing execution #1", BatchStatus.COMPLETED,
execution1.getBatchStatus());
Metric[] metrics = step.getMetrics();
Reporter.log("Testing the read count for execution #1<p>");
for (int i = 0; i < metrics.length; i++) {
if (metrics[i].getType().equals(Metric.MetricType.READ_SKIP_COUNT)) {
Reporter.log("AJM: in test, found metric: " + metrics[i].getType() + "<p>");
assertWithMessage(
"Testing the read skip count for execution #1", 4L,
metrics[i].getValue());
}
}
} catch (Exception e) {
handleException(METHOD, e);
}
}
示例13: testMetricsSkipWrite
import javax.batch.runtime.StepExecution; //导入方法依赖的package包/类
@Test
@org.junit.Test
public void testMetricsSkipWrite() throws Exception {
String METHOD = "testMetricsSkipWrite";
try {
Reporter.log("Create job parameters for execution #1:<p>");
Properties jobParams = new Properties();
Reporter.log("execution.number=1<p>");
Reporter.log("readrecord.fail=1,3<p>");
Reporter.log("app.arraysize=30<p>");
Reporter.log("numberOfSkips=2<p>");
Reporter.log("ReadProcessWrite=WRITE_SKIP<p>");
jobParams.put("execution.number", "1");
jobParams.put("writerecord.fail", "1,3,4");
jobParams.put("app.arraysize", "30");
jobParams.put("numberOfSkips", "3");
jobParams.put("ReadProcessWrite", "WRITE_SKIP");
Reporter.log("Locate job XML file: testMetricsSkipWriteCount.xml<p>");
Reporter.log("Invoke startJobAndWaitForResult for execution #1<p>");
JobExecution execution1 = jobOp.startJobAndWaitForResult("testMetricsSkipWriteCount",
jobParams);
Reporter.log("execution #1 JobExecution getBatchStatus()="
+ execution1.getBatchStatus() + "<p>");
Reporter.log("execution #1 JobExecution getExitStatus()="
+ execution1.getExitStatus() + "<p>");
assertWithMessage("Testing execution #1", BatchStatus.COMPLETED,
execution1.getBatchStatus());
List<StepExecution> stepExecutions = jobOp
.getStepExecutions(execution1.getExecutionId());
StepExecution step = null;
String stepNameTest = "step1";
for (StepExecution stepEx : stepExecutions) {
if (stepNameTest.equals(stepEx.getStepName())) {
step = stepEx;
}
}
Reporter.log("execution #1 JobExecution getBatchStatus()="
+ execution1.getBatchStatus() + "<p>");
assertWithMessage("Testing execution #1", BatchStatus.COMPLETED,
execution1.getBatchStatus());
Metric[] metrics = step.getMetrics();
Reporter.log("Testing the write skip count for execution #1<p>");
for (int i = 0; i < metrics.length; i++) {
if (metrics[i].getType().equals(Metric.MetricType.WRITE_SKIP_COUNT)) {
Reporter.log("AJM: in test, found metric: " + metrics[i].getType() + "<p>");
assertWithMessage(
"Testing the write skip count for execution #1", 3L,
metrics[i].getValue());
}
}
} catch (Exception e) {
handleException(METHOD, e);
}
}
示例14: testMetricsSkipProcess
import javax.batch.runtime.StepExecution; //导入方法依赖的package包/类
@Test
@org.junit.Test
public void testMetricsSkipProcess() throws Exception {
String METHOD = "testMetricsSkipProcess";
try {
Reporter.log("Create job parameters for execution #1:<p>");
Properties jobParams = new Properties();
Reporter.log("execution.number=1<p>");
Reporter.log("readrecord.fail=7,13<p>");
Reporter.log("app.arraysize=30<p>");
Reporter.log("numberOfSkips=2<p>");
Reporter.log("ReadProcessWrite=PROCESS<p>");
jobParams.put("execution.number", "1");
jobParams.put("processrecord.fail", "7,13");
jobParams.put("app.arraysize", "30");
jobParams.put("numberOfSkips", "2");
jobParams.put("ReadProcessWrite", "PROCESS");
Reporter.log("Locate job XML file: testMetricsSkipCount.xml<p>");
Reporter.log("Invoke startJobAndWaitForResult for execution #1<p>");
JobExecution execution1 = jobOp.startJobAndWaitForResult("testMetricsSkipCount",
jobParams);
Reporter.log("execution #1 JobExecution getBatchStatus()="
+ execution1.getBatchStatus() + "<p>");
Reporter.log("execution #1 JobExecution getExitStatus()="
+ execution1.getExitStatus() + "<p>");
assertWithMessage("Testing execution #1", BatchStatus.COMPLETED,
execution1.getBatchStatus());
assertWithMessage("Testing execution #1",
MetricsStepListener.GOOD_EXIT_STATUS_PROCESS,
execution1.getExitStatus());
List<StepExecution> stepExecutions = jobOp
.getStepExecutions(execution1.getExecutionId());
StepExecution step = null;
String stepNameTest = "step1";
for (StepExecution stepEx : stepExecutions) {
if (stepNameTest.equals(stepEx.getStepName())) {
step = stepEx;
}
}
Reporter.log("execution #1 JobExecution getBatchStatus()="
+ execution1.getBatchStatus() + "<p>");
assertWithMessage("Testing execution #1", BatchStatus.COMPLETED,
execution1.getBatchStatus());
Metric[] metrics = step.getMetrics();
Reporter.log("Testing the read count for execution #1<p>");
for (int i = 0; i < metrics.length; i++) {
if (metrics[i].getType().equals(Metric.MetricType.PROCESS_SKIP_COUNT)) {
Reporter.log("AJM: in test, found metric: " + metrics[i].getType() + "<p>");
assertWithMessage(
"Testing the read count for execution #1", 2L,
metrics[i].getValue());
}
}
} catch (Exception e) {
handleException(METHOD, e);
}
}
示例15: testReadMetric
import javax.batch.runtime.StepExecution; //导入方法依赖的package包/类
@Test
@org.junit.Test
public void testReadMetric() throws Exception {
String METHOD = "testReadMetric";
try {
Reporter.log("Create job parameters for execution #1:<p>");
Properties jobParams = new Properties();
Reporter.log("execution.number=1<p>");
Reporter.log("readrecord.fail=40<p>");
Reporter.log("app.arraysize=30<p>");
Reporter.log("app.chunksize=7<p>");
Reporter.log("app.commitinterval=10<p>");
Reporter.log("numberOfSkips=0<p>");
Reporter.log("ReadProcessWrite=READ<p>");
jobParams.put("execution.number", "1");
jobParams.put("readrecord.fail", "-1");
jobParams.put("app.arraysize", "30");
Reporter.log("Locate job XML file: testChunkMetrics.xml<p>");
Reporter.log("Invoke startJobAndWaitForResult for execution #1<p>");
JobExecution execution1 = jobOp.startJobAndWaitForResult("testMetricCount",
jobParams);
Reporter.log("execution #1 JobExecution getBatchStatus()="
+ execution1.getBatchStatus() + "<p>");
Reporter.log("execution #1 JobExecution getExitStatus()="
+ execution1.getExitStatus() + "<p>");
List<StepExecution> stepExecutions = jobOp
.getStepExecutions(execution1.getExecutionId());
StepExecution step = null;
String stepNameTest = "step1Metric";
for (StepExecution stepEx : stepExecutions) {
if (stepNameTest.equals(stepEx.getStepName())) {
step = stepEx;
}
}
Reporter.log("execution #1 JobExecution getBatchStatus()="
+ execution1.getBatchStatus() + "<p>");
assertWithMessage("Testing execution #1", BatchStatus.COMPLETED,
execution1.getBatchStatus());
Metric[] metrics = step.getMetrics();
Reporter.log("Testing the read count for execution #1<p>");
for (int i = 0; i < metrics.length; i++) {
if (metrics[i].getType().equals(Metric.MetricType.READ_COUNT)) {
Reporter.log("AJM: in test, found metric: " + metrics[i].getType() + "<p>");
assertWithMessage(
"Testing the read count for execution #1", 9L,
metrics[i].getValue());
}
}
} catch (Exception e) {
handleException(METHOD, e);
}
}