I finally decided to follow up on my "Congratulations, You have been signed up with Cloudfoundry" email and see if I can go flying in the cloud. I looked at the help doc and started following along.
You'd have to install ruby and ruby gems, unless you opt for the STS plugin. The Cloudfoundry's deploy tool vmc is a gem so the first thing I did was "gem install vmc" as per the help doc.
After that I went on to deploying my hello world grails app. Attached is a screen shot of my dos session:
And sure enough the world's best online donkeys supermarket can be found at:
http://onlinedonkeys.cloudfoundry.com
I didn't have to install a database, I didn't have to write code to talk to a proprietary data source (hint, hint...GAE). It all just magically worked. Thumbs up!
I like the fact that it gives you three options for database - MongoDB and redis besides MySQL.
It also automatically detected that I wanted to deploy a Grails app.
You can also deploy Rails, Node, Sinatra, Spring Roo and JavaWeb.
Happy clouding!
Sunday, May 22, 2011
Sunday, May 8, 2011
javax.mail.MessagingException: A12 NO Mailbox does not exist, or must be subscribed to
This one has been a long time coming...
One of the apps I have worked on uses Postfix + IMAP for email. One of the users was unable to get to her/his mailbox and in the apps logs for that user we were seeing :
Caused by: javax.mail.MessagingException: A12 NO Mailbox does not exist, or must be subscribed to.;
nested exception is:
com.sun.mail.iap.CommandFailedException: A12 NO Mailbox does not exist, or must be subscribed to.
at com.sun.mail.imap.IMAPFolder.getMessageCount(IMAPFolder.java:1206)
at com.altair.cls.common.messaging.eis.mail.MailMessageDAO.getMailBoxLineItem(MailMessageDAO.java:1083)
at com.altair.cls.common.messaging.eis.mail.MailMessageDAO.getMailBoxLineItems(MailMessageDAO.java:1020)
... 50 more
Caused by: com.sun.mail.iap.CommandFailedException: A12 NO Mailbox does not exist, or must be subscribed to.
at com.sun.mail.iap.Protocol.handleResult(Protocol.java:340)
at com.sun.mail.imap.protocol.IMAPProtocol.status(IMAPProtocol.java:855)
at com.sun.mail.imap.IMAPFolder.getStatus(IMAPFolder.java:1359)
at com.sun.mail.imap.IMAPFolder.getMessageCount(IMAPFolder.java:1185)
We give users the ability to create custom mail folders and subfolders. This particular one did create a custom folder and also a subfolder inside it, so the mailbox on the files system had the likes of:
Then at some point she/he attempted to delete the custom folder "CustomFolder" in this case, but something bleeped in the system and the parent "CustomFolder" was deleted, but the child "CustomFolder.subfolderOfCustomFolder" remained in the filesystem:
So the next time the user attempted to access her/his mailbox, she/he was unable to and the above mentioned exception was showing in the logs. We could not figure out what caused the subfolder to not delete, but deleting the subfolder, in this case "CustomFolder.subfolderOfCustomFolder", from the file system enabled the user to access her/his mailbox again. Hope this helps someone at some point.
One of the apps I have worked on uses Postfix + IMAP for email. One of the users was unable to get to her/his mailbox and in the apps logs for that user we were seeing :
Caused by: javax.mail.MessagingException: A12 NO Mailbox does not exist, or must be subscribed to.;
nested exception is:
com.sun.mail.iap.CommandFailedException: A12 NO Mailbox does not exist, or must be subscribed to.
at com.sun.mail.imap.IMAPFolder.getMessageCount(IMAPFolder.java:1206)
at com.altair.cls.common.messaging.eis.mail.MailMessageDAO.getMailBoxLineItem(MailMessageDAO.java:1083)
at com.altair.cls.common.messaging.eis.mail.MailMessageDAO.getMailBoxLineItems(MailMessageDAO.java:1020)
... 50 more
Caused by: com.sun.mail.iap.CommandFailedException: A12 NO Mailbox does not exist, or must be subscribed to.
at com.sun.mail.iap.Protocol.handleResult(Protocol.java:340)
at com.sun.mail.imap.protocol.IMAPProtocol.status(IMAPProtocol.java:855)
at com.sun.mail.imap.IMAPFolder.getStatus(IMAPFolder.java:1359)
at com.sun.mail.imap.IMAPFolder.getMessageCount(IMAPFolder.java:1185)
We give users the ability to create custom mail folders and subfolders. This particular one did create a custom folder and also a subfolder inside it, so the mailbox on the files system had the likes of:
Then at some point she/he attempted to delete the custom folder "CustomFolder" in this case, but something bleeped in the system and the parent "CustomFolder" was deleted, but the child "CustomFolder.subfolderOfCustomFolder" remained in the filesystem:
So the next time the user attempted to access her/his mailbox, she/he was unable to and the above mentioned exception was showing in the logs. We could not figure out what caused the subfolder to not delete, but deleting the subfolder, in this case "CustomFolder.subfolderOfCustomFolder", from the file system enabled the user to access her/his mailbox again. Hope this helps someone at some point.
Saturday, May 7, 2011
Wish list for things to play with after Stir Treck
1. Node.js
2. MongoDB (already played with, but just a little)
3. Finish reading JavaScript The Good Parts (...this is embarrassing, I've had this book for 8 months and it is only 140 pages)
4. Jasmine
5. Sinatra
6. Hadoop
2. MongoDB (already played with, but just a little)
3. Finish reading JavaScript The Good Parts (...this is embarrassing, I've had this book for 8 months and it is only 140 pages)
4. Jasmine
5. Sinatra
6. Hadoop
Sunday, March 6, 2011
Testing private methods in Java
In a perfect world you shouldn't need to test private methods in Java. If you are doing greenfield and you have committed to Test Driven Development, the unit test you write for your public and protected methods should be robust enough to cover the private methods as well. Legacy code is a different animal. Having to deal with spaghetti code, combined with a fast approaching deadline and the risk and effort in completely refactoring the whole thing, justifies the use of an utility for testing private methods...in my humble opinion that is. Here is one I have used plus an example:
import java.lang.reflect.Method;
public class PrivateMethodTestingUtil {
public static Object invokePrivateMethod(Object objectWithPrivateMethod, String methodName, Class[] classArgs , Object[] objectArgs) throws Exception {
Method privateMethod = objectWithPrivateMethod.getClass().getDeclaredMethod(methodName, classArgs);
privateMethod.setAccessible(true);
return privateMethod.invoke(objectWithPrivateMethod, objectArgs);
}
}
example
@Test
public void ensureValidatePasswordReturnsTrue() throws Exception{
User user = new User();
user.setPassword("password");
user.setConfirmPassword("password");
String someStringForASecondArg = "secondArg";
boolean validate = PrivateMethodTestingUtil.invokePrivateMethod(validator,
"validatePassword", new Class[]{User.class, String.class},
new Object[]{user, someStringForASecondArg});
assertTrue(validate);
}
public class Validator {
public boolean validate(User user) {
return validatePassword(User, "hello");
}
private boolean validatePassword(User user, String secondArg) {
return true;
}
}
import java.lang.reflect.Method;
public class PrivateMethodTestingUtil {
public static Object invokePrivateMethod(Object objectWithPrivateMethod, String methodName, Class[] classArgs , Object[] objectArgs) throws Exception {
Method privateMethod = objectWithPrivateMethod.getClass().getDeclaredMethod(methodName, classArgs);
privateMethod.setAccessible(true);
return privateMethod.invoke(objectWithPrivateMethod, objectArgs);
}
}
example
@Test
public void ensureValidatePasswordReturnsTrue() throws Exception{
User user = new User();
user.setPassword("password");
user.setConfirmPassword("password");
String someStringForASecondArg = "secondArg";
boolean validate = PrivateMethodTestingUtil.invokePrivateMethod(validator,
"validatePassword", new Class[]{User.class, String.class},
new Object[]{user, someStringForASecondArg});
assertTrue(validate);
}
public class Validator {
public boolean validate(User user) {
return validatePassword(User, "hello");
}
private boolean validatePassword(User user, String secondArg) {
return true;
}
}
Monday, February 28, 2011
Java regex to match words with only Alphanumeric and Punctuation characters
The title says it:
private static final String onlyAlphaNumericAndPunctuationRegex = "[\\p{Alnum}\\p{Punct}]*";
//returns true
"0123!\"#$%&<=~abcijkxyzABC".matches(onlyAlphaNumericAndPunctuationRegex);
//returns false
"hello test space".matches(onlyAlphaNumericAndPunctuationRegex);
//returns false
"some_àèìòù-ÀÈÌÒÙ_more".matches(onlyAlphaNumericAndPunctuationRegex);
if you need to have at least one character change the regex to:
"[\\p{Alnum}\\p{Punct}]{1,}";
private static final String onlyAlphaNumericAndPunctuationRegex = "[\\p{Alnum}\\p{Punct}]*";
//returns true
"0123!\"#$%&<=~abcijkxyzABC".matches(onlyAlphaNumericAndPunctuationRegex);
//returns false
"hello test space".matches(onlyAlphaNumericAndPunctuationRegex);
//returns false
"some_àèìòù-ÀÈÌÒÙ_more".matches(onlyAlphaNumericAndPunctuationRegex);
if you need to have at least one character change the regex to:
"[\\p{Alnum}\\p{Punct}]{1,}";
Friday, February 11, 2011
org.apache.abdera.parser.ParseException: com.ctc.wstx.exc.WstxException: Illegal null byte in input stream
Got this at work a couple of weeks ago, just got around putting it out here.
We use abdera1.0 to parse XML from a restful call:
org.apache.abdera.parser.stax.FOMParser feedParser = new org.apache.abdera.parser.stax.FOMParser();
InputStream in =new URL("http://randomdonkeys.com/give_me_my_donkey.atom").openStream();
Document<Feed> feedDoc = feedParser.parse(in);
The .parse call threw the WstxException. After digging around discovered that the abdera1.0 jar has issues with parsing ChunckedInputStream. I was able to get around it by wrapping the InputStream in InputStreamReader:
Document<Feed> feedDoc = feedParser.parse(new InputStreamReader(in));
Hope this helps someone at some point.
We use abdera1.0 to parse XML from a restful call:
org.apache.abdera.parser.stax.FOMParser feedParser = new org.apache.abdera.parser.stax.FOMParser();
InputStream in =new URL("http://randomdonkeys.com/give_me_my_donkey.atom").openStream();
Document<Feed> feedDoc = feedParser.parse(in);
The .parse call threw the WstxException. After digging around discovered that the abdera1.0 jar has issues with parsing ChunckedInputStream. I was able to get around it by wrapping the InputStream in InputStreamReader:
Document<Feed> feedDoc = feedParser.parse(new InputStreamReader(in));
Hope this helps someone at some point.
Tuesday, December 21, 2010
Data Providers - good or bad?
At work we use TestNG. It has the ability to do DataProviders for your unit tests :
TestNG DataProviders
JUnit 4 also allows you to do DataProviders.
I don't think DataProviders play very well with the notion of "self documenting code". I take it as self documenting code is not only the absence of JavaDoc and comments, not only variable and method names that make sense, but also unit tests that help you understand how the unit of code behaves under different circumstances.
As a developer on a new project which test would help you better figure out what the code does?
This:
or this:
@Test
public void ensureHasGreenCardReturnsFalseWhenNameIsBoyko() {
assertFalse( immigrationServiceUnderTest.hasGreenCard("Boyko");
}
TestNG DataProviders
JUnit 4 also allows you to do DataProviders.
I don't think DataProviders play very well with the notion of "self documenting code". I take it as self documenting code is not only the absence of JavaDoc and comments, not only variable and method names that make sense, but also unit tests that help you understand how the unit of code behaves under different circumstances.
As a developer on a new project which test would help you better figure out what the code does?
This:
@DataProvider(name = "greenCardData")
public Object[][] getGreenCardData() {
return new Object[][] {
{"Boyko", false}, {"Vladimir", true},{ "Borat", true},{ "Ricky Bobby", true} }; }
@Test(dataProvider = "greenCardData")
public void testHasGreenCard(String name, boolean expectedValue) {
assertEquals(expectedValue, immimgrationServiceUnderTest.hasGreenCard(name));
}or this:
@Test
public void ensureHasGreenCardReturnsFalseWhenNameIsBoyko() {
assertFalse( immigrationServiceUnderTest.hasGreenCard("Boyko");
}
@Test
public void ensureHasGreenCardReturnsTrueWhenNameIsNotBoyko() {
assertTrue( immigrationServiceUnderTest.hasGreenCard("John Madden");
}
In my opinion, if I am a new developer on a team and I happen to not have worked with data providers before, it would be easier and faster to pick up the domain specifics following the wordier, dataProviderless version.
On the flip side though, if I need to test a method whose args could have many possible values and return many possible values, the data provider way becomes more useful.
@DataProvider(name = "additionData")
public Object[][] getAdditionData() {
return new Object[][] {
{2, 2, 4}, {3, 3, 6},{ 5, 6, 11},{ 8, 10, 18}, {40, 60, 100} }; }
@Test(dataProvider = "additionData")
public void testAddNumbers(int number1, int number2, int result) {
assertEquals(result, additionServiceUnderTest.addNumbers(number1, number2));
}
Subscribe to:
Posts (Atom)

