AccessDeniedException in JUnit test using a TemporaryFolder - java

I'm having an issue with a JUnit test I made. The method I'm testing takes an InputStream should throw an exception if the passed InputStream doesn't support mark/reset.
The problem I am running into is that my test to ensure an exception gets thrown when an InputStream that doesn't support mark/reset gets passed (posted below) keeps throwing an AccessDeniedException.
public class IOTest{
#Rule
public TemporaryFolder tempFolder = TemporaryFolder()
#Before
public void createFolder() throws IOException {
Files.createDirectories(tempFolder.getRoot().toPath().resolve("testFile"));
}
#Test(expected = IllegalArgumentException.class)
public void testDetectCharsetOnlyAcceptsMarkResetSupportedInputStreams() throws IOException {
final Path testPath = tempFolder.getRoot().toPath().resolve("testFile");
final InputStream testStream = Files.newInputStream(testPath);
IO.detectCharset(testStream);
}
}
I think the problem I'm running into has to do with accessing the temporary folder, but I don't know how to circumvent this.
Here is the stack trace that gets printed when I run this test:
java.lang.Exception: Unexpected exception, expected<java.lang.IllegalArgumentException> but was<java.nio.file.AccessDeniedException>
at org.junit.internal.runners.statements.ExpectException.evaluate(ExpectException.java:28)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
at org.junit.rules.ExternalResource$1.evaluate(ExternalResource.java:48)
at org.junit.rules.RunRules.evaluate(RunRules.java:20)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.apache.maven.surefire.junit4.JUnit4Provider.execute(JUnit4Provider.java:252)
at org.apache.maven.surefire.junit4.JUnit4Provider.executeTestSet(JUnit4Provider.java:141)
at org.apache.maven.surefire.junit4.JUnit4Provider.invoke(JUnit4Provider.java:112)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at org.apache.maven.surefire.util.ReflectionUtils.invokeMethodWithArray(ReflectionUtils.java:189)
at org.apache.maven.surefire.booter.ProviderFactory$ProviderProxy.invoke(ProviderFactory.java:165)
at org.apache.maven.surefire.booter.ProviderFactory.invokeProvider(ProviderFactory.java:85)
at org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:115)
at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:75)
Caused by: java.nio.file.AccessDeniedException: C:\Users\antho\AppData\Local\Temp\junit4390480127201295432\testFile
at sun.nio.fs.WindowsException.translateToIOException(WindowsException.java:83)
at sun.nio.fs.WindowsException.rethrowAsIOException(WindowsException.java:97)
at sun.nio.fs.WindowsException.rethrowAsIOException(WindowsException.java:102)
at sun.nio.fs.WindowsFileSystemProvider.newByteChannel(WindowsFileSystemProvider.java:230)
at java.nio.file.Files.newByteChannel(Files.java:361)
at java.nio.file.Files.newByteChannel(Files.java:407)
at java.nio.file.spi.FileSystemProvider.newInputStream(FileSystemProvider.java:384)
at java.nio.file.Files.newInputStream(Files.java:152)
at com.bunnell.anthony.booker.IOTest.testDetectCharsetOnlyAcceptsMarkResetSupportedInputStreams(IOTest.java:65)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at org.junit.internal.runners.statements.ExpectException.evaluate(ExpectException.java:19)
... 24 more
I'm guessing it has something to do with permissions and the OS, but I'm just not sure how to get around this problem. If it helps, I'm using Windows 10.

You're trying to read from testFile, which is not a file but a directory; you're creating with
Files.createDirectories(tempFolder.getRoot().toPath().resolve("testFile"));
whose documentation says:
Creates a directory by creating all nonexistent parent directories first.
(emphasis mine)

In order to keep your JUnit tests portable and simple, I would suggest removing the external file dependency entirely.
You can do this in two ways:
Create an InputStream from something internal, like a String or byte array. Here is how with strings
Use a mocking framework, such as Mockito, to create a dummy InputStream that has just enough functionality to confirm that the method works. This would be my preferred strategy, as mocking produces much cleaner tests.

Related

What is the current best practice for testing a DoFn that use MapState

I'm writing a piece of dataflow transform that uses org.apache.beam.sdk.state.MapState to implement caching functionality. However upon introducing MapState, the unit test starts to dysfunction. The exception says: java.lang.UnsupportedOperationException: Parameter StateParameter{referent=StateDeclaration{id=cache, field=private final org.apache.beam.sdk.state.StateSpec xxxxFn.cache, stateType=org.apache.beam.sdk.state.MapState<java.lang.String, object>}} not supported by DoFnTester
So if DoFnTester is no longer an option, what is the current best practice for testing a DoFn that use MapState?
P.S. I'm currently on Beam 2.0.0, and I can't upgrade to 2.2.0 because https://issues.apache.org/jira/browse/BEAM-3693
Here is the complete Trace:
java.lang.UnsupportedOperationException: Parameter StateParameter{referent=StateDeclaration{id=cache, field=private final org.apache.beam.sdk.state.StateSpec xxxxFn.cache, stateType=org.apache.beam.sdk.state.MapState<java.lang.String, object>}} not supported by DoFnTester
at org.apache.beam.sdk.transforms.DoFnTester$5.dispatchDefault(DoFnTester.java:725)
at org.apache.beam.sdk.transforms.DoFnTester$5.dispatchDefault(DoFnTester.java:710)
at org.apache.beam.sdk.transforms.reflect.DoFnSignature$Parameter$Cases$WithDefault.dispatch(DoFnSignature.java:255)
at org.apache.beam.sdk.transforms.reflect.DoFnSignature$Parameter.match(DoFnSignature.java:193)
at org.apache.beam.sdk.transforms.DoFnTester.<init>(DoFnTester.java:709)
at org.apache.beam.sdk.transforms.DoFnTester.of(DoFnTester.java:92)
at xxxxFnTest.testNormalRun(GetPredictionsFnTest.java:50)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:564)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:86)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:538)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:760)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:460)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:206)
The Java DirectRunner is the best way to test your DoFn, whatever features it uses.
Using DoFnTester will enable you to gain false confidence by testing scenarios that are not feasible while missing scenarios that can really happen. For this reason, and bugs / lack of maintenance, DoFnTester is now deprecated and you should try to move off of it.
To have control over watermarks, the processing clock, and element bundling, you can use TestStream as described on the Beam blog.

Unable to find LoginModule class: com.sun.security.auth.module.UnixLoginModule

Trying to access HDFS location using Kerberose authentication, but getting below error message:
java.io.IOException: failure to login
at org.apache.hadoop.security.UserGroupInformation.loginUserFromSubject(UserGroupInformation.java:839)
at org.apache.hadoop.security.UserGroupInformation.getLoginUser(UserGroupInformation.java:775)
at org.apache.hadoop.security.UserGroupInformation.getCurrentUser(UserGroupInformation.java:648)
at org.apache.hadoop.fs.FileSystem$Cache$Key.<init>(FileSystem.java:2859)
at org.apache.hadoop.fs.FileSystem$Cache$Key.<init>(FileSystem.java:2851)
at org.apache.hadoop.fs.FileSystem$Cache.get(FileSystem.java:2714)
at org.apache.hadoop.fs.FileSystem.get(FileSystem.java:382)
at org.apache.hadoop.fs.FileSystem.get(FileSystem.java:181)
at com.xyz.module.submodule.common.utils.HDFSPropertyLookup.loadProperties(HDFSPropertyLookup.java:75)
at com.xyz.module.submodule.common.utils.HDFSPropertyLookup.initialize(HDFSPropertyLookup.java:37)
at com.xyz.module.submodule.common.utils.HDFSPropertyLookupTest.initializePropertiesFile(HDFSPropertyLookupTest.java:16)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:24)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.apache.maven.surefire.junit4.JUnit4Provider.execute(JUnit4Provider.java:252)
at org.apache.maven.surefire.junit4.JUnit4Provider.executeTestSet(JUnit4Provider.java:141)
at org.apache.maven.surefire.junit4.JUnit4Provider.invoke(JUnit4Provider.java:112)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.apache.maven.surefire.util.ReflectionUtils.invokeMethodWithArray(ReflectionUtils.java:189)
at org.apache.maven.surefire.booter.ProviderFactory$ProviderProxy.invoke(ProviderFactory.java:165)
at org.apache.maven.surefire.booter.ProviderFactory.invokeProvider(ProviderFactory.java:85)
at org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:115)
at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:75)
Caused by: javax.security.auth.login.LoginException: unable to find LoginModule class: com.sun.security.auth.module.UnixLoginModule
at javax.security.auth.login.LoginContext.invoke(LoginContext.java:794)
at javax.security.auth.login.LoginContext.access$000(LoginContext.java:195)
at javax.security.auth.login.LoginContext$4.run(LoginContext.java:682)
at javax.security.auth.login.LoginContext$4.run(LoginContext.java:680)
at java.security.AccessController.doPrivileged(Native Method)
at javax.security.auth.login.LoginContext.invokePriv(LoginContext.java:680)
at javax.security.auth.login.LoginContext.login(LoginContext.java:587)
at org.apache.hadoop.security.UserGroupInformation.loginUserFromSubject(UserGroupInformation.java:813)
... 31 more
Cause: LoginModule class: com.sun.security.auth.module.UnixLoginModule not found.
Want to know in which .jar file com.sun.security.auth.module.UnixLoginModule is present?
If someone might have faced this issue before, then please let help!
This issue got resolved!
Let me share the real cause and how it got resolved?
In unit test code, I was setting the os.name system property value to different operating system for my test case scenario as below:
System.setProperty("os.name", "Windows");
I was setting above properties value with Windows/Unix/MAC etc, but I missed to reset to its original value.
In same project there I was executing FileSystem.get(new Configuration()); from Hadoop API, in which Kerberose authentication was set.
So while execution operating system name was getting changed to some other name and it was not reset to original name.
Solution:
So in setup method I collected the original OS name to some other variable and after all test case completion reset to original name as below:
#BeforeClass
public static void setup() throws IOException {
System.setProperty("os.name.orig", System.getProperty("os.name"));
}
// other test case methods continue...
#AfterClass
public static void clearProperties() throws IOException {
System.setProperty("os.name", System.getProperty("os.name.orig"));
System.clearProperty("os.name.orig");
}
After above setting OS was reverted back to its original name and everything started working properly.
Hope this will help others in future!!!

Mockito Test RecyclerView Click Error

I have a test with Mockito from my RecyclerView clicks, but an error is thrown.
This is my code:
#Test
public void getUserClick() {
RecyclerView rcv = Mockito.mock(RecyclerView.class);
List<User> usersList = new ArrayList<>();
User commonUser = Mockito.mock(User.class);
commonUser.setId("1");
commonUser.setName("User");
commonUser.setEmail("admin#admin.com");
usersList.add(commonUser);
UserAdapterTest adapter = Mockito.mock(UserAdapterTest.class);
adapter.addData(usersList);
rcv.setAdapter(adapter);
// Test Click
rcv.getChildAt(0).performClick();
//Verify Click Item
Mockito.verify(adapter).testClickItem(commonUser);
}
And the error launch here:
java.lang.NullPointerException in rcv.getChildAt(0).performClick();
But the IDE doesn't tell me anything else.
java.lang.NullPointerException
at com.project.test.TestRecycler.getUserClick(TestRecycler.java:48)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at org.mockito.internal.junit.JUnitRule$1.evaluateSafely(JUnitRule.java:63)
at org.mockito.internal.junit.JUnitRule$1.evaluate(JUnitRule.java:43)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:117)
at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:42)
at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:262)
at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:84)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:147)
And my adapter already has the click event implemented.
When you do:
RecyclerView rcv = Mockito.mock(RecyclerView.class);
rcv becomes a mock (an object that returns null (or 0, or false) by default, on any method call). So rcv.getChildAt(0) by default is returning null, and when you try to call performClick() on it, the NullPointerException occurs.
When you create a mock and want some method to return a specific value, you must tell it using Mockito.when(). So in your case, you should do something like this:
// configure "when" behaviour **before** calling the getChildAt() method
Mockito.when(rcv.getChildAt(0)).thenReturn(objectYouWantToBeReturned);
Obviously you need to create objectYouWantToBeReturned before using when.
The code above will make rcv.getChildAt(0) returns the object you want, but only if you call it with parameter 0.
If you want to return the same object for any value (not only 0), you can do:
Mockito.when(rcv.getChildAt(Mockito.anyInt())).thenReturn(objectYouWantToBeReturned);
This will return objectYouWantToBeReturned for all calls of getChildAt, no matter what's the parameter value.

Strange error on running pigunit sample test

I'm trying to setup the pig unit tests and I was looking into the documentation which they've provided. It seems a bit outdated so I switched to the svn trunk. The first strange thing is that actually it needs some more libs, not only pigunit, pig and hadoop-commons in order to work(add hadoop-hdfs, hadoop-mapreduce-client-core, hadoop-mapreduce-client-jobclient). I'm not sure that having these in my dependency manager is something good but this is not the main problem. So here's the test I'm trying to execute:
#Test
public void testNtoN() throws ParseException, IOException {
String[] args = {
"n=3",
"reducers=1",
"input=top_queries_input_data.txt",
"output=top_3_queries",
};
test = new PigTest("script dir", args);
String[] output = {
"(yahoo,25)",
"(facebook,15)",
"(twitter,7)",
};
test.assertOutput("queries_limit", output);
}
And here's the actual script:
data =
LOAD '$input'
AS (query:CHARARRAY, count:INT);
queries_group =
GROUP data
BY query
PARALLEL $reducers;
queries_sum =
FOREACH queries_group
GENERATE
group AS query,
SUM(data.count) AS count;
queries_ordered =
ORDER queries_sum
BY count DESC
PARALLEL $reducers;
queries_limit = LIMIT queries_ordered $n;
STORE queries_limit INTO '$output';
Here's the stacktrace:
STORE queries_limit INTO 'top_3_queries';
--> none
org.apache.pig.impl.logicalLayer.FrontendException: ERROR 1066: Unable to open iterator for alias queries_limit
at org.apache.pig.PigServer.openIterator(PigServer.java:1019)
at org.apache.pig.pigunit.PigTest.getAliasFromCache(PigTest.java:224)
at org.apache.pig.pigunit.PigTest.getActualResults(PigTest.java:319)
at org.apache.pig.pigunit.PigTest.assertOutput(PigTest.java:409)
at org.apache.pig.pigunit.PigTest.assertOutput(PigTest.java:400)
at BlaUnitTest.testBla(BlaUnitTest.java:24)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:271)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:70)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)
at org.junit.runners.ParentRunner.run(ParentRunner.java:309)
at org.mockito.internal.runners.JUnit45AndHigherRunnerImpl.run(JUnit45AndHigherRunnerImpl.java:37)
at org.mockito.runners.MockitoJUnitRunner.run(MockitoJUnitRunner.java:62)
at org.junit.runner.JUnitCore.run(JUnitCore.java:160)
at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:117)
at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:42)
at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:262)
at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:84)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:147)
Caused by: java.io.IOException: Couldn't retrieve job.
at org.apache.pig.PigServer.store(PigServer.java:1083)
at org.apache.pig.PigServer.openIterator(PigServer.java:994)
... 34 more
I tried to debug it to see what actually happens and this occurs when it tries to build the query plan and acquire the ExecJob but I couldn't figure it out. I even tried to simplify the script and remove everything but the code for loading and storing the data. The result was the same.
I succeeded to resolve the issue. The problem was that I had included some dependencies in the classpath which seems to mess up the correct execution. The only needed dependencies are hadoop-core(I'm using hadoop-aws because I'm using it with aws), hadoop-client, pig and pigunit. So now everything is running correctly.

AssertionError on totally unrelated line of code - Junit test for school project

I am working on a Java RMI project and I am trying to begin to test the code I've written and when I run the following code, I get an AssertionError on a line that doesn't even have an assertion statement. I am confused as to how to fix this.
public void basicTest() throws UnknownHostException, RemoteException, AlreadyBoundException, NotBoundException, InterruptedException {
int numBooks = 20;
int copiesPerBook = 5;
int booksPerMember = 4;
// Simulate the server
LibraryServerImpl library = new LibraryServerImpl(numBooks, copiesPerBook, booksPerMember);
LibraryServer stub = (LibraryServer) java.rmi.server.UnicastRemoteObject.exportObject(library, 0);
Registry registry = LocateRegistry.createRegistry(port);
registry.bind(libraryName, stub);
// Simulate the client
Member member = new MemberImpl();
assertNotNull(member.getName()); // Will fail until you implement MemberImpl
Thread t = new Thread(new BasicClient(member));
t.start();
t.join();
}
This is the copied trace:
java.lang.AssertionError
at org.junit.Assert.fail(Assert.java:86)
at org.junit.Assert.assertTrue(Assert.java:41)
at org.junit.Assert.assertNotNull(Assert.java:712)
at org.junit.Assert.assertNotNull(Assert.java:722)
at PublicTests.basicTest(PublicTests.java:56)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:675)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)
Line 56 corresponds to registry.bind(libraryName, stub);
Clearly, this does not make sense, so one of the facts is false.
Fact: you got the above stack trace. --no reason to doubt the truthfulness of this fact.
Fact: PublicTests.java is written by you. --no reason to doubt the truthfulness of this fact.
Fact: line 56 of PublicTests.java corresponds to registry.bind(libraryName, stub). Well, this cannot be true, since according to the stack trace, the failure is detected by a call to org.junit.Assert.assertNotNull(), but the line registry.bind(libraryName, stub) is not an invocation of org.junit.Assert.assertNotNull().
However, further down in your code you do have an invocation of assertNotNull(member.getName()), which means that this must be what is being reported as line 56.
So, what you are looking at is a mismatch in the line number being reported in the stack trace. As user indivisible suggested, please refresh your project, clean your output folder, rebuild all projects, and try again.

Categories

Resources