Trying to run one of apache sparks example codes (https://github.com/apache/spark/blob/master/examples/src/main/scala/org/apache/spark/examples/graphx/AggregateMessagesExample.scala) I get the following compile error
too many arguments for method sendToDst: (msg: (Int, Double))Unit
[error] Error occurred in an application involving default arguments.
[error] triplet.sendToDst(1, triplet.srcAttr)
[error] ^
[error] one error found
But looking at the mehtods it seems to be correct. Not sure what is wrong here.
It looks like the method you are calling expects a single argument (a Tuple2) and you are passing in 2 arguments.
Try
triplet.sendToDst((1, triplet.srcAttr))
Related
From a Scala program, I need to send values with different primitive types to a Node server.
Http("http://middleware-api:3000/createPromoCodeInCms?")
.postForm
.param("lifetime", 5)
.method("POST")
.asString
This does not compile:
[error] /Users/corbac/Desktop/spark-projects/App.scala:192:24: type mismatch;
[error] found : Int(5)
[error] required: String
[error] .param("lifetime", 5)
[error] ^
However it seems like only strings are accepted as body parameters. Is it possible to post non-string types such as a number or a boolean? If yes how do I do it?
I am using Scala 2.11.
With playframework 2.6, I am getting following errors. I have read and found this error only on older versions, that too resolved easily.
[error] /Users/vishalupadhyay/Work/app/views/login_form.scala.html:12:22: ambiguous implicit values:
[error] both method implicitJavaMessages in object PlayMagicForJava of type => play.api.i18n.Messages
[error] and value request of type play.api.mvc.MessagesRequestHeader
[error] match expected type play.api.i18n.MessagesProvider
[error] #helper.inputText(loginForm("password"))
[error] ^
Could not find any answer which can help it. Please see complete code in this link.
Remove the implicit Lang and Messages arguments
I have a pretty complex test where I decided to go with approach of partial stubbing of tested class. in my test I have something like this:
val srv = new Service()
val srvSpy = spy(srv)
doReturn(now).when(srvSpy).getRunDateInTimeZone(futureChecklist)
doReturn("boo").when(srvSpy).interpolateChecklistName("name", now)
val returnTuple = (createdChlRev, createdChl)
doReturn(returnTuple).when(srvSpy).create(fChlCreatorId,
fChlCreatorEmail,
"username",
true,
templateId,
"boo",
optDueDate)(connection)
val (chlRev, chl) = srv.createFromFutureChecklist(futureChecklist)(connection)
In the code above, the first two stubbed methods working as expected. However, the last one throws an error:
[error] Tuple2 cannot be returned by create$default$8() [error]
create$default$8() should return JsObject [error] *** [error] If
you're unsure why you're getting above error read on. [error] Due
to the nature of the syntax above problem might occur because: [error]
1. This exception might occur in wrongly written multi-threaded tests. [error] Please refer to Mockito FAQ on limitations of
concurrency testing. [error] 2. A spy is stubbed using
when(spy.foo()).then() syntax. It is safer to stub spies - [error]
- with doReturn|Throw() family of methods. More in javadocs for Mockito.spy() method.
I've trying bunch of different approached of stubbing and still getting the same error. At this point I have no idea even where to look.
What am I doing wrong?
Any advice would be helpful.
Thanks
Sorry, it was my own dumb mistake. I was stubbing the spied class, but calling the original one :(
Thanks,
This works
(x => s"$x")
but this
(s"${_}")
results in
[error] ...: unbound placeholder parameter
[error] (s"${_}")
Is this a case of leaky abstraction?
Furthermore: (s"$_") fails with a completely different output:
[error] ...: invalid string interpolation: `$$', `$'ident or `$'BlockExpr expected
[error] (s"$_")
[error] ^
[error] ...: unclosed string literal
[error] (s"$_")
Calling string interpolation a leaky abstraction is totally right in my opinion. While it works fine in most cases, there are many edge cases where it just doesn't work the way how one expects it. This one is another incarnation of such an edge case.
I don't know why s"$_" is not accepted by the compiler. Some time ago there were a pull request that introduced this syntax for pattern matching: PR 2823
Interestingly this PR also contains test cases that test that the underscore outside of a pattern match produces an error.
Unfortunately there is no further description why this is implemented the way it is implemented.
Som Snytt, the guy who implemented the PR is active on SO, hopefully he can tell more.
I'm trying to assign groups to TestNG classes and methods in a Scala environment (in Eclipse)
#Test(groups="register")
class RegisterTest {
...
but am encountering the following error:
Multiple markers at this line
- type mismatch; found : java.lang.String("register") required:
Array[java.lang.String]
- annotation argument needs to be a constant; found: "register"{<error>}
I've tried applying groups to individual Scala methods but still encounter the same error.
Any suggestions on how to get around this?
The#Testannotation works as long as it doesn't specify any parameters (same error if dependsOnMethodsparameter is specified).
#DataProviderannotation also works.
The ScalaDoc gives the following example:
#Test(groups = Array("com.mycompany.groups.SlowTest"))
def funTest() {
sb.append("fun!")
assert(sb.toString === "ScalaTest is fun!")
assert(lb.isEmpty)
}
That seems to match the error you get.