001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: *
017: */
018:
019: /*
020: * N.B. Although this is a type of sampler, it is only used by the transaction controller,
021: * and so is in the control package
022: */
023: package org.apache.jmeter.control;
024:
025: import org.apache.jmeter.samplers.AbstractSampler;
026: import org.apache.jmeter.samplers.Entry;
027: import org.apache.jmeter.samplers.SampleResult;
028: import org.apache.jmeter.samplers.Sampler;
029:
030: /**
031: * Transaction Controller to measure transaction times
032: *
033: */
034: public class TransactionSampler extends AbstractSampler {
035: private boolean transactionDone = false;
036:
037: private TransactionController transactionController;
038:
039: private Sampler subSampler;
040:
041: private SampleResult transactionSampleResult;
042:
043: private int calls = 0;
044:
045: private int noFailingSamples = 0;
046:
047: public TransactionSampler() {
048: //log.warn("Constructor only intended for use in testing");
049: }
050:
051: public TransactionSampler(TransactionController controller,
052: String name) {
053: transactionController = controller;
054: setName(name); // ensure name is available for debugging
055: transactionSampleResult = new SampleResult();
056: transactionSampleResult.setSampleLabel(name);
057: // Assume success
058: transactionSampleResult.setSuccessful(true);
059: transactionSampleResult.sampleStart();
060: }
061:
062: /**
063: * One cannot sample the TransactionSample directly.
064: */
065: public SampleResult sample(Entry e) {
066: // It is the JMeterThread which knows how to sample a
067: // real sampler
068: return null;
069: }
070:
071: public Sampler getSubSampler() {
072: return subSampler;
073: }
074:
075: public SampleResult getTransactionResult() {
076: return transactionSampleResult;
077: }
078:
079: public TransactionController getTransactionController() {
080: return transactionController;
081: }
082:
083: public boolean isTransactionDone() {
084: return transactionDone;
085: }
086:
087: public void addSubSamplerResult(SampleResult res) {
088: // Another subsample for the transaction
089: calls++;
090: // The transaction fails if any sub sample fails
091: if (!res.isSuccessful()) {
092: transactionSampleResult.setSuccessful(false);
093: noFailingSamples++;
094: }
095: // Add the sub result to the transaction result
096: transactionSampleResult.addSubResult(res);
097: }
098:
099: protected void setTransactionDone() {
100: this .transactionDone = true;
101: // Set the overall status for the transaction sample
102: // TODO: improve, e.g. by adding counts to the SampleResult class
103: transactionSampleResult
104: .setResponseMessage("Number of samples in transaction : "
105: + calls
106: + ", number of failing samples : "
107: + noFailingSamples);
108: if (transactionSampleResult.isSuccessful()) {
109: transactionSampleResult.setResponseCodeOK();
110: }
111: }
112:
113: protected void setSubSampler(Sampler subSampler) {
114: this.subSampler = subSampler;
115: }
116: }
|