Compile Error on line r.db("test").tableCreate("authors").run(conn); - rethinkdb-javascript

I have setup Rethinkdb to use and I am trying to connect to DB via Java program using Java Driver.
I downloaded RethinkDB java driver 2.3.1 from http://mvnrepository.com/artifact/com.rethinkdb/rethinkdb-driver/2.3.1.
But I am getting the following compile error in this simple program.
Can you please tell why I am getting this compile error?
//Code Line
r.db("test").tableCreate("authors").run(conn);
//Compile error in eclipse
Multiple markers at this line
- Syntax error, insert ")" to complete SingleMemberAnnotation
- Syntax error, insert ")" to complete MethodDeclaration
- Syntax error, insert "Identifier (" to complete
MethodHeaderName
- Syntax error on token ")", delete this token
- Syntax error, insert "SimpleName" to complete QualifiedName
- Syntax error on token ".", # expected after this token
Complete program
package com.test;
import com.rethinkdb.RethinkDB;
import com.rethinkdb.gen.exc.ReqlError;
import com.rethinkdb.gen.exc.ReqlQueryLogicError;
import com.rethinkdb.model.MapObject;
import com.rethinkdb.net.Connection;
public class DbConnection {
public static final RethinkDB r = RethinkDB.r;
Connection conn= r.connection().hostname("localhost").port(28015).connect();
r.db("test").tableCreate("authors").run(conn);
}

You cannot put statements into the class body, you need to move them into a method.

Related

Jmeter BeanShellSampler error: Error invoking bsh method: eval import org.apache.commons.io.FileUtils

I use BeanShell code loading 100s of sql files in jmeter:
import org.apache.commons.io.FileUtils;
File folder = new File("D:\\sql99");
File[] sqlFiles = folder.listFiles();
for (int i = 0; i < sqlFiles.length; i++) {
File sqlFile = sqlFiles[i];
if (sqlFile.isFile()) {
vars.put("query_" + i,sqlFile.getName(),
FileUtils.readFileToString(sqlFiles[i]));
}
}
but get error info :
17:42:03,301 ERROR o.a.j.u.BeanShellInterpreter: Error invoking bsh method: eval Sourced file: inline evaluation of: ``import org.apache.commons.io.FileUtils; File folder = new File("D:\sql99"); Fi . . . '' : Error in method invocation: Method put( java.lang.String, java.lang.String, java.lang.String ) not found in class'org.apache.jmeter.threads.JMeterVariables'
I want to get each sql execute time in jmeter results tree. How to fix code?
Thanks!
You're trying to call JMeterVariables.put() function which accepts 2 Strings as the parameters passing 3 Strings
The correct syntax is vars.put("variable-name", "variable-value"); so you need to decide how to amend this line:
vars.put("query_" + i, sqlFile.getName(), FileUtils.readFileToString(sqlFiles[i]));
so it would contain only 2 parameters instead of 3.
Also since JMeter 3.1 it's recommended to use JSR223 Test Elements and Groovy language for scripting mainly for performance reasons so it might be a good option for switching (the same code will work in Groovy without changes assuming you fix the issue with vars.put() function call)

How to graphql-codegen handle schema with string templates in typescript/javascript exports

I am using graphql-codegen to generate the typescript type files for given schema.
All good except if there is string template in the exported scheme, it will complain the sytax and seems it will not compile it. Check the following files for more details.
The types.js is below:
const gql = require("graphql-tag");
const Colors = ["Red", "Yellow"];
export default gql`
type Person {
name: String
}
enum Color {
${Colors.join("\n")}
}
# if we change the above enum to be the below, it will be good
# enum Color {
# Red
# Yellow
# }
`;
And the config yml file is:
schema:
- types.js
generates:
generated.ts:
plugins:
- typescript
- typescript-resolvers
When run yarn graphql:codegen, it complains the below:
Found 1 error
✖ generated.ts
Failed to load schema from types.js:
Syntax Error: Expected Name, found }
GraphQLError: Syntax Error: Expected Name, found }
at syntaxError (/Users/rliu/study/reproduce-graphql-codegen-with-string-template-in-js-export/node_modules/graphql/error/syntaxError.js:15:10)
at Parser.expectToken (/Users/rliu/study/reproduce-graphql-codegen-with-string-template-in-js-export/node_modules/graphql/language/parser.js:1404:40)
at Parser.parseName (/Users/rliu/study/reproduce-graphql-codegen-with-string-template-in-js-export/node_modules/graphql/language/parser.js:94:22)
at Parser.parseEnumValueDefinition (/Users/rliu/study/reproduce-graphql-codegen-with-string-template-in-js-export/node_modules/graphql/language/parser.js:1014:21)
at Parser.optionalMany (/Users/rliu/study/reproduce-graphql-codegen-with-string-template-in-js-export/node_modules/graphql/language/parser.js:1497:28)
at Parser.parseEnumValuesDefinition (/Users/rliu/study/reproduce-graphql-codegen-with-string-template-in-js-export/node_modules/graphql/language/parser.js:1002:17)
at Parser.parseEnumTypeDefinition (/Users/rliu/study/reproduce-graphql-codegen-with-string-template-in-js-export/node_modules/graphql/language/parser.js:986:23)
at Parser.parseTypeSystemDefinition (/Users/rliu/study/reproduce-graphql-codegen-with-string-template-in-js-export/node_modules/graphql/language/parser.js:705:23)
at Parser.parseDefinition (/Users/rliu/study/reproduce-graphql-codegen-with-string-template-in-js-export/node_modules/graphql/language/parser.js:146:23)
at Parser.many (/Users/rliu/study/reproduce-graphql-codegen-with-string-template-in-js-export/node_modules/graphql/language/parser.js:1518:26)
at Parser.parseDocument (/Users/rliu/study/reproduce-graphql-codegen-with-string-template-in-js-export/node_modules/graphql/language/parser.js:111:25)
at Object.parse (/Users/rliu/study/reproduce-graphql-codegen-with-string-template-in-js-export/node_modules/graphql/language/parser.js:36:17)
at Object.parseGraphQLSDL (/Users/rliu/study/reproduce-graphql-codegen-with-string-template-in-js-export/node_modules/#graphql-toolkit/common/index.cjs.js:572:28)
at CodeFileLoader.load (/Users/rliu/study/reproduce-graphql-codegen-with-string-template-in-js-export/node_modules/#graphql-toolkit/code-file-loader/index.cjs.js:120:31)
at async /Users/rliu/study/reproduce-graphql-codegen-with-string-template-in-js-export/node_modules/#graphql-toolkit/core/index.cjs.js:682:25
at async Promise.all (index 0)
GraphQL Code Generator supports:
- ES Modules and CommonJS exports (export as default or named export "schema")
- Introspection JSON File
- URL of GraphQL endpoint
- Multiple files with type definitions (glob expression)
- String in config file
Try to use one of above options and run codegen again.
Error: Failed to load schema
at loadSchema (/Users/rliu/study/reproduce-graphql-codegen-with-string-template-in-js-export/node_modules/#graphql-codegen/cli/bin.js:353:15)
Error: Failed to load schema
at loadSchema (/Users/rliu/study/reproduce-graphql-codegen-with-string-template-in-js-export/node_modules/#graphql-codegen/cli/bin.js:353:15)
Looks like graphql-codegen didn't like template string like: ${Colors.join('\n')}.
Also please have a look about the repo containing all the above files.
Anyone can help to fix? Thanks.
It's not handling it, mostly because of the complexity of loading code files and interpolate it.
But, the way to workaround is:
Create a single schema.js file.
Import all typedefs with string interpolation from your source files, and use buildSchema (from graphql) or makeExecutableSchema (from graphql-tools) to build a GraphQLSchema object instance.
Export your GraphQLSchema as default export, or as identifier named schema.
Provide that file into codegen (by doing schema: ./schema.js - using a single code file causes the codegen to look for ast code, and then try to do require to it.
If you are using TypeScript, you should also add require extension to the codegen (see https://graphql-code-generator.com/docs/getting-started/require-field#typescript-support)

How to delete files on Windows with Rapture IO

I'm writing Scala code. What is the correct path schema for writing a URI when using Rapture to operate with files on Windows? I have added the following dependencies:
libraryDependencies += "com.propensive" %% "rapture" % "2.0.0-M3" exclude("com.propensive","rapture-json-lift_2.11")
Here is part of my code:
import rapture.uri._
import rapture.io._
val file = uri"file:///C:/opt/eric/spark-demo"
file.delete()
but I got the message:
Error:(17, 16) value file is not a member of object rapture.uri.UriContext
val file = uri"file:///C:/opt/eric/spark-demo"
or I tried this one:
val file = uri"file://opt/eric/spark-demo"
The same error:
Error:(17, 16) value file is not a member of object rapture.uri.UriContext
val file = uri"file://opt/eric/spark-demo"
And my local path is:
C:\opt\eric\spark-demo
How can I avoid the error?
You're missing an import:
import rapture.io._
import rapture.uri._
import rapture.fs._
val file = uri"file:///C:/opt/eric/spark-demo"
file.delete()
rapture.fs is the package defining an EnrichedFileUriContext implicit class, which is what the uri macro trys to build when being provided with a file URI scheme.

Beanshell Script throws error while running from terminal but it runs perfectly in GUI mode in JMETER

I tried to run the following script:
import org.apache.commons.io.FileUtils; // necessary import
int lines = FileUtils.readLines(new File("${testPlanFileDir}/csv/test_smtp_save.csv")).size() - 1; // get lines count
vars.put("lines", String.valueOf(lines)); // store the count into "lines" variable
To get the number of lines in my csv, so that I can execute a loop according to the number of lines in the CSV file.
The script above runs perfectly if I run from GUI mode, but when I run from terminal then it throws following error.
ERROR - jmeter.util.BeanShellInterpreter: Error invoking bsh method: eval
Sourced file: inline evaluation of:
``import org.apache.commons.io.FileUtils; // necessary import int lines = FileUtil . . . ''
: Typed variable declaration : Method Invocation FileUtils.readLines
How do you get this ${testPlanFileDir} variable value? Apart from it the code looks good.
If you want to have more relevant error message you can try putting your code into the try block:
import org.apache.commons.io.FileUtils;
try {
int lines = FileUtils.readLines(new File("${testPlanFileDir}/csv/test_smtp_save.csv")).size() - 1;
vars.put("lines", String.valueOf(lines));
}
catch (Throwable ex) {
log.error("Error in Beanshell", ex);
throw ex;
}
And look into jmeter.log file - it will contain the "usual" stacktrace.
Alternatively you can add debug() command to the very beginning of your Beanshell script - it will toggle debugging output to stdout
See How to Use BeanShell: JMeter's Favorite Built-in Component for more Beanshell-related tips and tricks
Replace ${testPlanFileDir} by:
vars.get("testPlanFileDir")
You should avoid using Beanshell in favor of JSR223+Groovy+Cache which is embedded in JMeter 3.0, see:
http://jmeter.apache.org/changes.html
https://www.ubik-ingenierie.com/blog/jmeter_performance_tuning_tips/
I used this to get the current directory of .jmx file.
Declared varaible TestPlanFileDir as;
${__BeanShell(import org.apache.jmeter.services.FileServer; FileServer.getFileServer().getBaseDir();)}${__BeanShell(File.separator,)}

JMeter / Beanshell "Error invoking bsh method: eval Sourced file:"

I'm having an issue in JMeter wherein I receive this error
2014/08/14 14:13:26 ERROR - jmeter.util.BeanShellInterpreter: Error invoking bsh method: eval Sourced file: inline evaluation of: ``String RequestUrl = vars.get("RequestUrl"); String[] params = RequestUrl.split(" . . . '' : Typed variable declaration
2014/08/14 14:13:26 WARN - jmeter.extractor.BeanShellPostProcessor: Problem in BeanShell script org.apache.jorphan.util.JMeterException: Error invoking bsh method: eval Sourced file: inline evaluation of: ``String RequestUrl = vars.get("RequestUrl"); String[] params = RequestUrl.split(" . . . '' : Typed variable declaration
I have no clue whats wrong, and the code otherwise seems to be working. Can anyone give me some advice?
Here is the block of code in question:
String RequestUrl = vars.get("RequestUrl");
String[] params = RequestUrl.split("\\?");
String RequestTask = params[1].split("\\&")[1].split("=")[1];
System.out.println(RequestTask);
vars.put("RequestTask",RequestTask);
it should probably be mentioned that the code is in a post processor, which is paired with an Xpath extractor for "RequestUrl"
Edited to include entire error
I don't see your URL and what does XPath query return but in any case your URL parsing logic looks flaky as it strongly dependent on parameters order and presence and may bite you back in future in case of request URL change i.e. extra parameter or changed parameters order or something encoded, etc.
See below for reference:
import org.apache.http.NameValuePair;
import org.apache.http.client.utils.URLEncodedUtils;
import java.net.URI;
import java.util.List;
String url = vars.get("RequestUrl");
List params = URLEncodedUtils.parse(new URI(url), "UTF-8");
for (NameValuePair param : params) {
if (param.getName().equals("put your actual param name here")) {
vars.put("RequestTask", param.getValue());
}
}
Also it worth checking out How to use BeanShell: JMeter's favorite built-in component for troubleshooting tips. In general to localize error logging should be used like:
log.info("something");
log.error("something else");
So if you don't see message in the log than Beanshell wasn't able to execute the line and failed somewhere above.
Also Beanshell error messages aren't very informative, I use the following construction in my scripts:
try {
//script logic here
}
catch (Throwable ex) {
log.error("Failed to do this or that", ex);
}
So error stracktrace could be read in jmeter.log file.
Hope this helps.
Could you show the whole error?
Try adding one statement after the other to see which one is root cause.
I suppose you may be making hypothesis on results (array access) which may be cause of issue.
if you are coverting a VuGen recorded JMS script to JMeter, then you have to look for the lr functions copied which WILL throw this/similar error.
For eg: int orderlinecount = Integer.parseInt(lr.eval_string("strInt"));
You have to make sure your script is free of all lr - related functions in order for the jmeter to successfully executed your script.

Resources