Test Dataflow with DirectRunner and got lots of verifyUnmodifiedThrowingCheckedExceptions - google-cloud-dataflow

I was testing my Dataflow pipeline using DirectRunner from my Mac and got lots of "WARNING" message like this, may I know how to get rid of them because it is too much that I can not even see my debug message.
Thanks
Apr 05, 2018 2:14:48 PM org.apache.beam.sdk.util.MutationDetectors$CodedValueMutationDetector verifyUnmodifiedThrowingCheckedExceptions
WARNING: Coder of type class org.apache.beam.sdk.coders.SerializableCoder has a #structuralValue method which does not return true when the encoding of the elements is equal.
Element com.apigee.analytics.platform.core.service.schema.EventRow#4a590d0b

It may help to ensure that all serialized values have proper equals() implementations since SerializableCoder expects them:
The structural value of the object is the object itself. The SerializableCoder should be only used for objects with a proper Object#equals implementation.
You can implement your own Coder for your POJOs. SerializableCoder does not guarantee a deterministic encoding according to docs:
SerializableCoder does not guarantee a deterministic encoding, as Java
serialization may produce different binary encodings for two equivalent
objects.
This article explains custom coders in details.

I had this same problem. I was using SerializableCoder for a class implementing Serializable, and my tests were failing because the PAssert() containsInAnyOrder() method was not using MyClass.equals() to evaluate object equality. The signature of my equals() method was:
public boolean equals(MyClass other) {...}
All I had to do to fix it was to define equals in terms of Object:
public boolean equals(Object other) {...}
This made the warnings go away, and made the tests pass.

Just add
https://projectlombok.org/features/EqualsAndHashCode
#EqualsAndHashCode
public class YourRecord implements Serializable {

Related

How does Orika decide when to use converter

I am trying to understand when does Orika use converters to do the mapping versus direct casting.
I have the following mapping:
Class A {
Map<String, Object> props;
}
Class B {
String bStr;
int bInt;
}
My mapping is defined as props['aStr'] => bStr and props['aInt'] => bInt
When I look at the generated code, I see that for the String case, it uses a converter and calls its convert method for the transformation:
destination.setBStr("" + ((ma.glasnost.orika.Converter)usedConverters[0]).convert(
((java.lang.Object) ((java.util.Map) source.getProps().get("aStr"),
(ma.glasnost.orika.metadata.Type) usedTypes[0]))
But, for the integer case it directly casts it like this:
destination.setBInt((java.lang.Integer)(java.lang.Object) ((java.util.Map)
source.getProps().get("aInt")))
The above line of code ends up giving class cast exception.
For fixing this issue, I was thinking along the lines of using a custom converter but if the above line of code doesn't use the converter then that wont work.
Of course, I can always do this is in my custom mapper but just trying to understand how the code is generated for type conversion.
Thanks!!
In Orika there is two stages: config-time and runtime, as optimization Orika resolve all used converter in the config-time and cache them into each generated mapper so it will be accessible directly O(1) but in the config time it will try to find in a list O(n) of registered converters which one "canConvert" between two given types, canConvert is a method in Converter interface .
So this solution offer the best of the two worlds:
A very flexible way to register a converter with arbitrary conditions
An efficient resolution and conversion operation in the runtime.
Orika by default, leverage the existence of .toString in every object to offer implicit coercion to String for every Object. The problem here is that there is no Converter from Object to Integer.
Maybe this can be an issue of error reporting. Ideally Orika should report that an Object have to be converted to Integer and there is no appropriate converter registered.

What parameters should be used for AbstractDeclarativeValidator.warning and error?

I have a working grammar on xtext, and am starting the validation of the code.
For this, I added a method in the validator xtext created for me.
Of course, when an expression isn't valid, I want to be able to give a warning on the given AST node.
I attempted the obvious:
#Check
public void testCheck(Expression_Multiplication m){
if(!(m.getLeft() instanceof Expression_Number)){
warning("Multiplication should be on numbers.",m.getLeft());
}
if(!(m.getRight() instanceof Expression_Number)){
warning("Multiplication should be on numbers.",m.getRight());
}
}
Without success, as Expression_Number extends EObject, but is not an EStructuralFeature.
warning(String message, EStructuralFeature feature)
There are many other prototypes for warning, but none that takes just a String and a Eobject. Using null or various values extracted from eContainingFeature logs an error, and sometimes shows the warning at the correct place anyway. Searching for examples, I found that the values were often coming from the statics fields of a class called Literals or ***Package, the one generated in the project contains EStructuralFeatures, but I have no idea of which one to use, or why I would need one of these.
So the question is:
How can I place a warning on a given AST element ?
The EStructuralFeature is the property of your AST. You'll find a generated EPackage class, which contains constants.
I guess in your case it is something like:
MyDslPackage.Literals.EXPRESSION_MULTIPLICATION__LEFT
and
MyDslPackage.Literals.EXPRESSION_MULTIPLICATION__RIGHT
I ended up using
private void warning(String text, EObject badAstNode){
// The -1 seems to come from a static member somewhere. Probably cleaner to
// name it, but I couldn't find it again.
warning(text,badAstNode,null,-1);
}
I have no idea about whether this is supposed to be the right way, but it seemed to work in the various cases I used it, and requires a minimal amount of state to be kept.

Attributes in Dart

Are there any plans to introduce attributes
for classes, methods, parameters of methods,
something like C# or Java attributes ?
[Test]
class SomeClass
{
[Test]
someMethod()
}
or
#Test
class SomeClass
{
#Test
someMethod(#Test int param)
}
For many frameworks it would be very useful
In dart, they are called metadata / annotation. The syntax is quite close to java. Here's a example :
#Test testMethod() {}
In Dart Specification you can read :
Metadata consists of a series of annotations, each of which begin with the character #, followed a constant expression that starts with an identifier. It is a compile time error if the expression is not one of the following:
A reference to a compile-time constant variable.
A call to a constant constructor.
[....]
Metadata can appear before a library, class, typedef, type parameter, constructor, factory, function, field, parameter, or variable declaration and before an import or export directive.
There're already some annotations predifined in dart:core. Particulary #override, #deprecated and #proxy.
Dart already has annotations, similar to Java in some ways, they're just not used in very many places yet, and they're not accessible from reflection yet either.
See this article: http://news.dartlang.org/2012/06/proposal-to-add-metadata-to-dart.html
Here's a brief introduction to the two metadata annotations currently available in the Dart meta library:
Dart Metadata is your friend.
This doesn't preclude you from using your own, but these are the two that have tooling integration with the Dart Editor.

"The type is not generic, it cannot be be parameterized with arguments"

I am trying to create a class implementing Blackberry's Comparator so I can easily sort 2D arrays.
import net.rim.device.api.util.Comparator;
class ArrayComparator implements Comparator<Object[]> {
...
}
This gives me the error:
The Type Comparator is not generic; it can not be parameterized with
arguments <Object[]>
This error goes away if I include the normal JRE library and import java.util.Comparator, but this won't compile because it is a mobile device, the library is not preverified, etc, etc, etc.
How can I resolve this issue?
net.rim.device.api.util.Comparator doesn't have Generic capabilities. You need to implement Comparator without any type information and compare all the items of the array. if the items of the array are objets, you need to implements the Comparator interface on this Objets too.
you can get more implementation information on this link
BlackBerry JRE is 1.3 (like CLDC 1.1) and don't support generics, non-synchronized collections and other things from modern java world.
Sicne you're defining a comparator for a particular class you don't need (and can't use) generics. Your array comparator should cast the Object type parameters to their corresponding type before comparing in the compare method you override.
For example, your ArrayComparator should cast o1 and o2 to an array. In the future if you make a, say, UserDataComparator the compare method should cast the parameters to your UserData class type.
FYI: Blackberry's compiler (RAPC) supports up to java 1.4 AFAIK (check this) so Generics, Enums and other Java 1.5 and above features are not supported.
EDIT As other persons pointed (and for the sake of a complete answer) I was not specific enough on my anwer. I have edited this answer to reflect some crucial points related to your issue.

Semantics of OMG IDL attributes

I'm working on the verification of an interface formalised in the OMG's IDL, and am having problems finding a definitive answer on the semantics of getting an attribute value. In an interface, I have an entry...
interface MyInterface {
readonly attribute SomeType someName;
};
I need to know if it is acceptable for someObj.someName != someObj.someName to be true (where someObj is an instance of an object implementing MyInterface).
All I can find in OMG documentation in regards to attributes is...
(5.14) An attribute definition is logically equivalent to declaring a
pair of accessor functions; one to retrieve the value of the attribute
and one to set the value of the attribute.
...
The optional readonly keyword indicates that there is only a single
accessor function—the retrieve value function.
Ergo, I'm forced to conclude that IDL attributes need not be backed by a data member, and are free to return basically any value the interface deems appropriate. Can anyone with more experience in IDL confirm that this is indeed the case?
As we know, IDL interface always will be represented by a remote object. An attribute is no more then a syntatic sugar for getAttributeName() and setAttributeName(). Personally, i don't like to use attribute because it is hardly to understand than a simply get/set method.
CORBA also has valuetypes, object by value structure - better explaned here. They are very usefull because, different from struct, allow us inherit from other valuetypes, abstract interface or abstract valuetype. Usualy, when i'm modeling objects with alot of
get/set methods i prefer to use valuetypes instead of interfaces.
Going back to your question, the best way to understand 'attribute' is looking for C#. IIOP.NET maps 'attribute' to properties. A property simulates a public member but they are a get/set method.
Answering your question, i can't know if someObj.someName != someObj.someName will return true or false without see the someObj implementation. I will add two examples to give an ideia about what we can see.
Example 1) This implementation will always return false for the expression above:
private static i;
public string getSomeName() {
return "myName" i;
}
Example 2) This implementation bellow can return true or false, depending of concurrency or 'race condition' between clients.
public string getSomeName() {
return this.someName;
}
public setSomeName(string name) {
this.someName = name;
}
First client can try to access someObj.someName() != someObj.someName(). A second client could call setSomeName() before de second call from the first client.
It is perfectly acceptable for someObj.someName != someObj.someName to be true, oddly as it may seem.
The reason (as others alluded to) is because attributes map to real RPC functions. In the case of readonly attributes they just map to a setter, and for non-readonly attributes there's a setter and a getter implicitly created for you when the IDL gets compiled. But the important thing to know is that an IDL attribute has a dynamic, server-dictated, RPC-driven value.
IDL specifies a contract for distributed interactions which can be made at runtime between independent, decoupled entities. Almost every interaction with an IDL-based type will lead to an RPC call and any return value will be dependent on what the server decides to return.
If the attribute is, say, currentTime then you'll perhaps get the server's current clock time with each retrieval of the value. In this case, someObj.currentTime != someObj.currentTime will very likely always be true (assuming the time granularity used is smaller than the combined roundtrip time for two RPC calls).
If the attribute is instead currentBankBalance then you can still have someObj.currentBankBalance != someObj.currentBankBalance be true, because there may be other clients running elsewhere who are constantly modifying the attribute via the setter function, so you're dealing with a race condition too.
All that being said, if you take a very formal look at the IDL spec, it contains no language that actually requires that the setting/accessing of an attribute should result in an RPC call to the server. It could be served by the client-side ORB. In fact, that's something which some ORB vendors took advantage of back in the CORBA heyday. I used to work on the Orbix ORB, and we had a feature called Smart Proxies - something which would allow an application developer to overload the ORB-provided default client proxies (which would always forward all attribute calls to the server hosting the target object) with custom functionality (say, to cache the attribute values and return a local copy without incurring network or server overhead).
In summary, you need to be very clear and precise about what you are trying to verify formally. Given the dynamic and non-deterministic nature of the values they can return (and the fact that client ORBs might behave differently from each other and still remain compliant to the CORBA spec) you can only reliably expect IDL attributes to map to getters and setters that can be used to retrieve or set a value. There is simply no predictability surrounding the actual values returned.
Generally, attribute does not need to be backed by any data member on the server, although some language mapping might impose such convention.
So in general case it could happen that someObj.someName != someObj.someName. For instance attribute might be last access time.

Resources