WARN net.spy.memcached.transcoders.SerializingTranscoder: Caught IOException decoding bytes of data

1

I started to get a weird exception
java.io.InvalidClassException: package.com.something.Some_Hibernate_Table; no valid constructor
at java.io.ObjectStreamClass.checkDeserialize(ObjectStreamClass.java:730)
.
.
.
Some_Hibernate_Table

The stack trace was very weird, it hinted at a launch stack, and a exception from a table other than what I was sending data to. Infact after doing some debugging, step by step, this exception happened on a get on a SomeOther_Hibernate_Table.

Crazy root cause.. 🙂
Old code
List tableRow = null ;
if (isCacheable) {
tableRow value = cache.get(key) ;
return tableRow
}
String rowQuery = “Select * from ” + tableName + ” where ” + column + “=” + “\”” + key + “\””;
Query rowResult = currentSession().createSQLQuery(rowQuery);
tableRow = rowResult.list();

The cache returns a Object, but hibernate.createSQLQuery returns a List. So to keep things clean, the fix below.
Object value = cache.get(key) ;
if (isCacheable) {
if (value != null) {
tableRow = new ArrayList() ;
tableRow.add(value);
return tableRow;
}
}
String rowQuery = “Select * from ” + tableName + ” where ” + column + “=” + “\”” + key + “\””;
Query rowResult = currentSession().createSQLQuery(rowQuery);
tableRow = rowResult.list();

Advertisements

Hibernate Class cast expection when reading items from createSQLQuery().list

0

Got some good advice from https://forum.hibernate.org/viewtopic.php?p=2393573
From
String tableQuery = “Select * from ” + tableName ;
Query tableResult = null;
List table = null;
tableResult = currentSession().createSQLQuery(tableQuery);
table = tableResult.list();

I modified the code to
String tableQuery = “Select {t.*} from ” + tableName + ” t”;
Query tableResult = null;
List table = null;
tableResult = currentSession().createSQLQuery(tableQuery).addEntity(“t”, tableClass);
table = tableResult.list();

Testing for Developers, necessary evil (developers/managers read this)

0

I have always wondered why developers fail to test their own code. It believe its a upbringing issue. If you have worked with people who care a lot about product quality, and value the fact that defects must be found early, you will write and plan unit testing into your development effort. Basically if you have spent time with talented folks you will do what it takes to get your code/design and data model right. You will understand the difference between throwing exceptions and printing error messages on screens. Also the ability to debug your app later will be on your mind.

Also seems like developers get the attitude from their seniors/teachers, who imply that Testing is for idiots, and the fact that they strongly believe that they are the only chosen ones who can do development. Infact I can be sure that developers who dont believe in testing their own code, spend countless hours mocking testers.

Now you can say that the system is to blame. Managers dont care about unit test cases, customers only care about their tests working, ultimately the business managers who care only about “time to market”. Infact so strong is the communication from top, is “time to market” is the only important criteria. Quality is recognized only if “time to market”, estimates and dates are maintained. And every person who had delivered a project knows that “time to market” never takes a hit, its the quality.

To clean up the system it takes someone to start. Developer is just as good as anyone to start.

I wont spend time convincing developers to unit test their code, or to write test cases. But I will spend time to help developers who are convinced about unit testing and guide them thru their challenges.

Challenge No 1 : What to test ?
Every class needs to be tested. A class is testable if you have simple small classes that do just the job they are suppose to do. Keep your classes simple and hence testable.

Challenge No 2 : When to test ?
When you have completed coding of your class. And all methods have clear inputs and outputs.

Challenge No 3 : I am stuck, just cant think.
First get your hands off your computer. Take a pen and pencil and start putting down mind maps, input scenarios, what ever help you think.. THINK!!!! Just collect your thoughts. Personally I use the white board. I put down tables, flow charts, just to collect my thoughts..

Challenge No 4 : What test cases to write
Here you need to refer to the basics of software engineering. Unit test cases is positive tests, negative tests and boundary conditions. Our mind can get easily confused. So lets take this step by step. Start simple, positive test cases. Then negative and finally boundary. If you are as crazy as I am, also do “equivalence partitioning” for data sets that is beyond testing.

Challenge No 5 : I cant think!!!
Yes this is a reality people, developers put in soo much of their analytical thinking while coding, that thinking testing (which is a lateral and destructive thought, is a pain). Creative Thinking uses up the entire brain. Drink water, lots of it. The brain needs oxygen to think, and water is the only way the brain gets its needed oxygen. Take a walk with a pencil in your hand. Just relax and collect your thoughts.

Challenge No 6 : Im still stuck!!
Reply to this blog, lets discuss. You need a mentor and someone to bang your head against, a sound board. I can be that for you. reply.. lets talk it out..

Finally I leave you with this thought.
DO A KICK ASS JOB, not just a job.. “Just Coding” is for idiots.. Its the real men (or women for that matter) who can write test cases..

(This blog helped me gather my thoughts http://stackoverflow.com/questions/83147/whats-wrong-with-foreign-keys, especially comment by Ed Lucas)

java.net.ConnectException : Connection refused

0

In my case, I was running a server socket on 127.0.0.1 on port xyz, and trying to get my clients to connect to it. It worked on one ubuntu machine, but failed to work on another.


serverSocket = new ServerSocket(serverPort, 500, Inet4Address.getByName("127.0.0.1"));

I changed this to 

serverSocket = new ServerSocket(serverPort, 500, Inet4Address.getLocalHost());

Thats it, started to fly again… 

java.net.ConnectException : Connection refused

0

In my case, I was running a server socket on 127.0.0.1 on port xyz, and trying to get my clients to connect to it. It worked on one ubuntu machine, but failed to work on another.

<code>

serverSocket = new ServerSocket(serverPort, 500, Inet4Address
.getByName(“127.0.0.1”));

</code>

I changed this to 

<code>

serverSocket = new ServerSocket(serverPort, 500, Inet4Address
.getLocalHost());

</code>

Thats it, started to fly again…