I am following the Code lab here https://developers.google.com/bigquery/articles/gettingstartedwithjava to make requests to big query. One of the code samples here says:
Datasets.List datasetRequest = bigquery.datasets().list(projectId);
DatasetList datasetList = datasetRequest.execute();
But I am getting a "The method execute() is undefined for the type Bigquery.Datasets.List" error.
Any idea whats going on?
I am on version google-api-services-bigquery-v2-rev42-1.12.0-beta if that matters.
You need to explicitly add this dependency to get it working. The dependency in the pom for google-api-services-bigquery seem to be wrong. Which causes this exception.
<dependency>
<groupId>com.google.api-client</groupId>
<artifactId>google-api-client</artifactId>
<version>1.12.0-beta</version>
</dependency>
Related
I've add Flink Hadoop Compatibility to the project which reads sequence file from hdfs path,
<dependency>
<groupId>org.apache.flink</groupId>
<artifactId>flink-hadoop-compatibility_2.11</artifactId>
<version>1.5.6</version>
</dependency>
Here's the java code snippet,
DataSource<Tuple2<NullWritable, BytesWritable>> input = env.createInput(HadoopInputs.readHadoopFile(
new org.apache.hadoop.mapreduce.lib.input.SequenceFileInputFormat<NullWritable, BytesWritable>(),
NullWritable.class, BytesWritable.class, path));
This works pretty fine when I run it inside my Eclipse, but when I submit it via command line 'flink run ...', it complains,
The type returned by the input format could not be automatically determined. Please specify the TypeInformation of the produced type explicitly by using the 'createInput(InputFormat, TypeInformation)' method instead.
OK, so I update my code to add type information,
DataSource<Tuple2<NullWritable, BytesWritable>> input = env.createInput(HadoopInputs.readHadoopFile(
new org.apache.hadoop.mapreduce.lib.input.SequenceFileInputFormat<NullWritable, BytesWritable>(),
NullWritable.class, BytesWritable.class, path),
TypeInformation.of(new TypeHint<Tuple2<NullWritable, BytesWritable>>() {}));
Now it complains,
Caused by: java.lang.RuntimeException: Could not load the TypeInformation for the class 'org.apache.hadoop.io.Writable'. You may be missing the 'flink-hadoop-compatibility' dependency.
Some people suggest to copy flink-hadoop-compatibility_2.11-1.5.6.jar to FLINK_HOME/lib, but it doesn't help, still same error.
Does anyone have any clue?
My Flink is a standalone installation, version 1.5.6.
UPDATE:
Sorry, I copied flink-hadoop-compatibility_2.11-1.5.6.jar to the wrong place, after fixing that, it works.
Now my question is, is there any other way to go? Because copying that jar file to FLINK_HOME/lib is definitely not a good idea to me, especially when talking about a big flink cluster.
Fixed in version 1.9.0, see https://issues.apache.org/jira/browse/FLINK-12163 for details
I am working on an app which uses GAE and GCS serverside. Among other things I can upload pictures and store their publicUrl in a google mysql database. Today I tried to use .secureUrl(true) when getting those publicUrls and since then I get a 500 server error when sending post requests.
I can break it down to the following code snippet:
public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException,
ServletException {
// create Writer for response
PrintWriter out = response.getWriter();
response.setContentType("application/json");
// create Database Connection url with name database, username and password
String mysqlUrl = System.getProperty("cloudsql");
// get 'operation' parameter to determine further action
String operation = request.getParameter("operation");
if (operation == null){ operation = "getFav"; }
GcsService gcsService = GcsServiceFactory.createGcsService();
When I dont comment out the last line where gcsService is set, every post request sent from my phone is answered with a 500 server error. If I make the line a comment, everything (except for the parts where gcs is used) works perfectly. Checking out the Google console, I get the following message:
java.lang.NoClassDefFoundError: com/google/appengine/api/utils/SystemProperty
at com.google.appengine.tools.cloudstorage.GcsServiceFactory.createRawGcsService (GcsServiceFactory.java:57)
at com.google.appengine.tools.cloudstorage.GcsServiceFactory.createGcsService (GcsServiceFactory.java:44)
at com.google.appengine.tools.cloudstorage.GcsServiceFactory.createGcsService (GcsServiceFactory.java:40)
at net.xyz.yzxI.HelloAppEngine.<init> (HelloAppEngine.java:69)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0 (Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance (NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance (DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance (Constructor.java:423)
at java.lang.Class.newInstance (Class.java:443)
at org.eclipse.jetty.server.handler.ContextHandler$Context.createInstance (ContextHandler.java:2481)
at org.eclipse.jetty.servlet.ServletContextHandler$Context.createServlet (ServletContextHandler.java:1327)
at org.eclipse.jetty.servlet.ServletHolder.newInstance (ServletHolder.java:1285)
at org.eclipse.jetty.servlet.ServletHolder.initServlet (ServletHolder.java:615)
at org.eclipse.jetty.servlet.ServletHolder.getServlet (ServletHolder.java:499)
at org.eclipse.jetty.servlet.ServletHolder.ensureInstance (ServletHolder.java:791)
at org.eclipse.jetty.servlet.ServletHolder.prepare (ServletHolder.java:776)
at org.eclipse.jetty.servlet.ServletHandler.doHandle (ServletHandler.java:579)
at org.eclipse.jetty.server.handler.ScopedHandler.handle (ScopedHandler.java:143)
at org.eclipse.jetty.security.SecurityHandler.handle (SecurityHandler.java:524)
at org.eclipse.jetty.server.session.SessionHandler.doHandle (SessionHandler.java:226)
at org.eclipse.jetty.server.handler.ContextHandler.doHandle (ContextHandler.java:1180)
at org.eclipse.jetty.servlet.ServletHandler.doScope (ServletHandler.java:512)
at org.eclipse.jetty.server.session.SessionHandler.doScope (SessionHandler.java:185)
at org.eclipse.jetty.server.handler.ContextHandler.doScope (ContextHandler.java:1112)
at org.eclipse.jetty.server.handler.ScopedHandler.handle (ScopedHandler.java:141)
at com.google.apphosting.runtime.jetty9.AppVersionHandlerMap.handle (AppVersionHandlerMap.java:297)
at org.eclipse.jetty.server.handler.HandlerWrapper.handle (HandlerWrapper.java:134)
at org.eclipse.jetty.server.Server.handle (Server.java:534)
at org.eclipse.jetty.server.HttpChannel.handle (HttpChannel.java:320)
at com.google.apphosting.runtime.jetty9.RpcConnection.handle (RpcConnection.java:202)
at com.google.apphosting.runtime.jetty9.RpcConnector.serviceRequest (RpcConnector.java:81)
at com.google.apphosting.runtime.jetty9.JettyServletEngineAdapter.serviceRequest (JettyServletEngineAdapter.java:108)
at com.google.apphosting.runtime.JavaRuntime$RequestRunnable.dispatchServletRequest (JavaRuntime.java:680)
at com.google.apphosting.runtime.JavaRuntime$RequestRunnable.dispatchRequest (JavaRuntime.java:642)
at com.google.apphosting.runtime.JavaRuntime$RequestRunnable.run (JavaRuntime.java:612)
at com.google.apphosting.runtime.JavaRuntime$NullSandboxRequestRunnable.run (JavaRuntime.java:806)
at com.google.apphosting.runtime.ThreadGroupPool$PoolEntry.run (ThreadGroupPool.java:274)
at java.lang.Thread.run (Thread.java:745)
It drives me crazy: Even if I dont use the gcs at all, just trying to set it up breaks the app. I have like no clue where to look at, so hopefully someone else has had similar experiences or knows what to check.
Thanks in advance
If you are using Maven to handle dependencies this error may be due to a "provided" in the com.google.appengine dependency. Remove that line in pom.xml so Maven will include app engine sdk in the compiled project.
Before:
<dependency>
<groupId>com.google.appengine</groupId>
<artifactId>appengine-api-1.0-sdk</artifactId>
<version>1.9.63</version>
<scope>provided</scope>
</dependency>
After:
<dependency>
<groupId>com.google.appengine</groupId>
<artifactId>appengine-api-1.0-sdk</artifactId>
<version>1.9.63</version>
</dependency>
I'm trying to use scalatest suite using intellij idea like this :
class SampleTest extends org.scalatest.Suite {
def myTest() {
assert(true)
}
}
(new SampleTest).execute()
I have added scalactic_2.11 and scalactic_2.11 to my pom file.The problem is that the SDK still cant resolve it.
Well it seems the problem is due to versioning. using the following version resolved the issue :
<dependency>
<groupId>org.scalatest</groupId>
<artifactId>scalatest</artifactId>
<version>0.9.5</version>
</dependency>
I am running the example Google spec, i.e:
class GoogleHomePageSpec extends GebReportingSpec {
def "first result for wikipedia search should be wikipedia"() {
given:
to GoogleHomePage
expect:
at GoogleHomePage
when:
search.field.value("wikipedia")
then:
waitFor { at GoogleResultsPage }
and:
firstResultLink.text().startsWith "Wikipedia"
when:
firstResultLink.click()
then:
waitFor { at WikipediaPage }
}
}
with the following GebSpec:
reportsDir = "target/geb-reports"
/* webdriver.*.driver system properties are set in the POM */
driver = {
new HtmlUnitDriver();
}
and the following relevant pom.xml excerpt:
<dependency>
<groupId>org.spockframework</groupId>
<artifactId>spock-core</artifactId>
<version>0.7-groovy-2.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>2.39.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.gebish</groupId>
<artifactId>geb-spock</artifactId>
<version>0.9.2</version>
<scope>test</scope>
</dependency>
and it fails with the message if I run it from CLI or IDE:
First result for wikipedia search should be wikipedia(scratch.GoogleHomePageSpec) Time elapsed: 0.96 sec <<< ERROR!
geb.driver.DriverCreationException: failed to create driver from callback 'GebConfig$_run_closure1#20fcbdaf'
at geb.driver.CallbackDriverFactory.getDriver(CallbackDriverFactory.groovy:35)
at geb.driver.CachingDriverFactory.getDriver_closure3(CachingDriverFactory.groovy:80)
at geb.driver.CachingDriverFactory.getDriver_closure3(CachingDriverFactory.groovy)
at geb.driver.CachingDriverFactory$SimpleCache.get(CachingDriverFactory.groovy:30)
at geb.driver.CachingDriverFactory.getDriver(CachingDriverFactory.groovy:79)
at geb.Configuration.createDriver(Configuration.groovy:354)
at geb.Configuration.getDriver(Configuration.groovy:343)
at geb.Browser.getDriver(Browser.groovy:105)
at geb.Browser.clearCookies(Browser.groovy:483)
at geb.Browser.clearCookiesQuietly(Browser.groovy:491)
at geb.spock.GebSpec.resetBrowser(GebSpec.groovy:45)
at geb.spock.GebSpec.cleanup(GebSpec.groovy:67)
Caused by: java.lang.NoClassDefFoundError: org/apache/commons/collections/set/ListOrderedSet
at com.gargoylesoftware.htmlunit.CookieManager.<init>(CookieManager.java:59)
at com.gargoylesoftware.htmlunit.WebClient.<init>(WebClient.java:131)
at org.openqa.selenium.htmlunit.HtmlUnitDriver.newWebClient(HtmlUnitDriver.java:289)
at org.openqa.selenium.htmlunit.HtmlUnitDriver.createWebClient(HtmlUnitDriver.java:263)
at org.openqa.selenium.htmlunit.HtmlUnitDriver.<init>(HtmlUnitDriver.java:144)
at GebConfig.run_closure1(GebConfig.groovy:10)
at GebConfig.run_closure1(GebConfig.groovy)
at geb.driver.CallbackDriverFactory.getDriver(CallbackDriverFactory.groovy:29)
at geb.driver.CachingDriverFactory.getDriver_closure3(CachingDriverFactory.groovy:80)
at geb.driver.CachingDriverFactory.getDriver_closure3(CachingDriverFactory.groovy)
at geb.driver.CachingDriverFactory$SimpleCache.get(CachingDriverFactory.groovy:30)
at geb.driver.CachingDriverFactory.getDriver(CachingDriverFactory.groovy:79)
at geb.Configuration.createDriver(Configuration.groovy:354)
at geb.Configuration.getDriver(Configuration.groovy:343)
at geb.Browser.getDriver(Browser.groovy:105)
at geb.Browser.clearCookies(Browser.groovy:483)
at geb.Browser.clearCookiesQuietly(Browser.groovy:491)
at geb.spock.GebSpec.resetBrowser(GebSpec.groovy:45)
at geb.spock.GebSpec.cleanup(GebSpec.groovy:67)
I've checked and the commons-collection jar is present and contains the 'missing' class.
I don't get this error at all using ChromeDriver, FirefoxDriver and InternetExplorerDriver.
Unfortunately for environmental reasons I have to use HtmlUnitDriver so I'm really scratching my head about this one.
Would be grateful for any suggestions.
EDIT 1:
Have managed to run a portion of this test successfully on my Mac, the remainder times out.
But am not seeing the same errors as above (which were observed on Windows).
Resolved this problem by rebuilding the maven_repo i.e. moving the old one out of the way so maven is forced to rebuild it on the next run of the tests.
The exception no longer appears.
Running the following unit test throws the exception: java.lang.IllegalStateException: no last call on a mock available
import org.easymock.*;
import org.junit.*;
public class MyTest {
#Test
public void testWithClass() {
Thread threadMock = EasyMock.createMock(Thread.class);
EasyMock.expect(threadMock.isAlive()).andReturn(true);
}
}
I am not sure what I am doing wrong and can not find any good examples on the web. How do you mock a class using EasyMock 3.0. What is wrong with the above unit test? Any help would be greatly appreciated.
My project includes the following maven dependencies
<dependency>
<groupId>org.easymock</groupId>
<artifactId>easymock</artifactId>
<version>3.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>cglib</groupId>
<artifactId>cglib-nodep</artifactId>
<version>2.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.objenesis</groupId>
<artifactId>objenesis</artifactId>
<version>1.2</version>
<scope>test</scope>
</dependency>
The reason for this exception is that Thread#isAlive() is a final method, but EasyMock does not support the mocking of final methods. So, the call to this method which appears inside EasyMock.expect(...) is not seen as a "call on a mock".
To mock final methods you would need a different mocking tool, such as JMockit (which I develop):
public void testMockingFinalMethod(#Mocked("isAlive") Thread mock)
{
new Expectations()
{{
mock.isAlive(); result = true;
}};
assertTrue(mock.isAlive());
}
The mocking API doesn't actually require that methods to be mocked are specified explicitly, in the general case. The Thread class is a tricky one, though.
Your test method looks fine, except that you have not prepared the mock object you have created. This has to be done using
EasyMock.replay(mockObject1, mockObject2, ...);
This will prepare the mocked object so that it is the one which will be used on running your JUnit. No issues with your dependencies as well.
Also, you don't seem to be calling the actual method which you are unit-testing here. Usually, the way to write a test method would be to write a JUnit method, using mocking libs
(such as EasyMock and PowerMock) ONLY when there are external objects beyond the test method context, and then replaying all the mocked objects (which prepares the mocks to substitute for the real business objects in the test). After that, you call the actual method you are trying to test, and validate the functionality using org.junit.Assert.assertXXX() methods.
I had multiple calls to EasyMock.replay(mock) within one test case or suite causing this issue, and calling EasyMock.reset(mock) between each solved the problem.