/** Returns last line of output from the command */ public SampleResult sample(Entry e) { SampleResult res = new SampleResult(); res.setSampleLabel( getName() + ":(" + getUsername() + "@" + getHostname() + ":" + getPort() + ")"); // Set up sampler return types res.setSamplerData(action + " " + source); res.setDataType(SampleResult.TEXT); res.setContentType("text/plain"); String response; if (getSession() == null) { connect(); } try { if (getSession() == null) { log.error( "Failed to connect to server with credentials " + getUsername() + "@" + getHostname() + ":" + getPort() + " pw=" + getPassword()); throw new NullPointerException("Failed to connect to server: " + getFailureReason()); } response = doFileTransfer(getSession(), source, destination, res); res.setResponseData(response.getBytes()); res.setSuccessful(true); res.setResponseMessageOK(); } catch (JSchException e1) { res.setSuccessful(false); res.setResponseCode("JSchException"); res.setResponseMessage(e1.getMessage()); } catch (SftpException e1) { res.setSuccessful(false); res.setResponseCode("SftpException"); res.setResponseMessage(e1.getMessage()); } catch (IOException e1) { res.setSuccessful(false); res.setResponseCode("IOException"); res.setResponseMessage(e1.getMessage()); } catch (NullPointerException e1) { res.setSuccessful(false); res.setResponseCode("Connection Failed"); res.setResponseMessage(e1.getMessage()); } finally { // Try a disconnect/sesson = null here instead of in finalize. disconnect(); setSession(null); } return res; }
public SampleResult sample(Entry arg0) { SampleResult result = new SampleResult(); result.setDataType(SampleResult.TEXT); result.setContentType("text/plain"); result.setSampleLabel(getName()); result.setSamplerData(query); // Assume we will be successful result.setSuccessful(true); result.setResponseMessageOK(); result.setResponseCodeOK(); Statement statement = configure(getStatement()); result.sampleStart(); // sampleStart() e sampleEnd() vengono usati da JMeter per calcolare i // response times try { /** * ORIGINALE - SINCRONO ResultSet data = getSession(keySpace).execute(statement); * result.setResponseData(getStringFrom(data).getBytes()); * result.setResponseMessage(data.toString()); */ /** Modifica 22/02/2016 - ASINCRONO * */ @SuppressWarnings("unused") ResultSetFuture datafuture = getSession(keySpace).executeAsync(statement); } catch (Exception ex) { log.error(String.format("Error executing CQL statement [%s]", getQuery()), ex); result.setResponseMessage(ex.toString()); result.setResponseData(ex.getMessage().getBytes()); result.setSuccessful(false); } result.sampleEnd(); return result; }