Monday, April 30, 2012

blogger bug: all time stats months are shifted on the graph

Funny, accidentally I was checking the stats on 1st of May at 12 + am local time, which seems to be different than blogger server time, when I was viewing all time stats,  the graph was shifting all months so it was showing April stats in May, March in April and so on.

image

Exercise: Finding Greatest Common Divisor (Euclidean Algorithm)

Finding the GCD for 2 numbers

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Numerics;


namespace CS
{
public static class Helpers
{
public static BigInteger GCD_Loop(BigInteger A, BigInteger B)
{
BigInteger R = BigInteger.One;
while (B != 0)
{
R = A % B;
A = B;
B = R;
}
return A;
}
public static BigInteger GCD_Euclidean(BigInteger A, BigInteger B)
{
if (B == 0)
return A;
if (A == 0)
return B;
if(A>B)
return GCD_Euclidean(B, A % B);
else
return GCD_Euclidean(B % A, A);
}
}
}

Friday, April 20, 2012

jmeter: adding assertions to validate correct response

During my test execution I noticed that some responses are getting the error page, for the jmeter is was http 200, so it marked the request as passed, this is not correct, this request should be failing, so I created assertion rule to identify these errors

In my case the error page has it’s own URL, so I added response assertion to check URL sampled not to contain “error”, steps to do so:

Right click on the thread group or the recording controller

Select add –> Assertions –> Response Assertions

image

Fill the Response Assertion properties:

Apply to: Main samples and sub samples (usually the error page comes as a sub page from the requested page)

Response Field to Test: URL Sampled (In my case the error is identified by the URL of the error page, in other cases the error can be a frame inside the response)

Pattern Matching Rules: Contains, make sure not is checked (This means I am asserting that my response URL is not the error URL)

Pattern to Test: error (in my case the URL to error contained the word error, in other cases it could be a specific text message inside the response)

Screenshot-2012-04-20_15.48.20

Adding the Assertion as above, while running, if any sub sample was the error page, it was marked as failed

Wednesday, April 18, 2012

jmeter: excluding resources while recording

it is better to exclude un-necessary resource while recording so that you don’t end up with hundreds of requests, and removing them later by selecting and deleting, will be exhausting task

Add the following to the HTTP Proxy Server settings

.*\.jpg

.*\.png

.*\.ico

.*\.css

.*\.gif

.*\.js

Screenshot-2012-04-18_17.14.00

Creating Trigger in DB2 Control Center

to create trigger in DB2 Control Center,

Open Control Center

Open the Database to display the database objects

Right click on triggers and select create

Screenshot-2012-04-18_15.50.44

Select the schema, table name

Select the time and operation

Screenshot-2012-04-18_15.50.20

Select triggered action tab

Enter the name for old row, name for new row

Enter the When conditions, and the required script to be executed after Begin Atomic

Screenshot-2012-04-18_15.51.05

Click Ok

Saturday, April 14, 2012

MS CRM4: Retrieving and parsing articles from CRM

We had some articles in CRM that was created on specific template for the purpose of displaying on public web site as bilingual FAQs.

The article template had 4 sections, 2 sections for English question and answer in English, and the other 2 sections for Arabic.

            List<kbarticle> results = new List<kbarticle>();

CrmService crmService = ServiceAssembly.GetCrmService();

QueryExpression query = new QueryExpression();
query.EntityName = "kbarticle";
query.ColumnSet = new ColumnSet(attributes);

query.Criteria.AddCondition(new ConditionExpression("statecode", ConditionOperator.Equal, KbArticleState.Published.ToString()));
query.Criteria.AddCondition(new ConditionExpression("kbarticletemplateid", ConditionOperator.Equal, _articleTemplate));
query.AddOrder("createdon", OrderType.Descending);

int count = 0;
foreach (kbarticle article in crmService.RetrieveMultiple(query).BusinessEntities)
{
count++;
results.Add(article);
if (count >= 5)
break;
}


First I retrieved the templates using the template ID that I created specifically for this purpose



now we have the results, we need to parse article xml for each article



                // We need to return back the question and the answer, whilst preserving
// the formatting of the actual answer.
// In addition, the correct language must be displayed (not both language types).

// Example string in contents:
// <articledata><section id='0'><content><![CDATA[test question english]]></content></section><section id='1'>
// <content><![CDATA[<P align=center>test answer english</P> <UL> <LI> <DIV align=center>Hello</DIV></LI>
// <LI> <DIV align=center>test</DIV></LI> <LI> <DIV align=center>test</DIV></LI></UL> <OL> <LI>Oh</LI>
// <LI>Dear</LI> <LI>My <FONT color=#ff0000><STRONG>ha ha ha</STRONG></FONT></LI></OL>]]></content>
// </section><section id='2'><content><![CDATA[<P align=center>السؤيبليب</P> <P align=center>&nbsp;يبليبلي سليبسليبللا</P>]]></content></section>
// <section id='3'><content><![CDATA[]]></content></section></articledata>

int questionSection = 0;
int answerSection = 1;

if (langugageCode == Lang.ARABIC)
{
questionSection = 2;
answerSection = 3;
}

// Load the article
XmlDocument x = new XmlDocument();
x.LoadXml(articleXML);

// Fetch the question
XmlNode node = x.SelectSingleNode("/articledata/section[@id='" + questionSection + "']/content");

// Question retrieval
string question = node.InnerText;
Tracer.WriteLine("question is: " + question);

// Fetch the answer
node = x.SelectSingleNode("/articledata/section[@id='" + answerSection + "']/content");

// Answer retrieval
string answer = node.InnerText;
Tracer.WriteLine("answer is: " + answer);

// Finally, set the Article class
parsedArticle.Question = question;
parsedArticle.Answer = answer;
parsedArticle.Language = langugageCode;
parsedArticle.ArticleID = articleID;


where parsedArticle is an object that holds the details that we are interested in.

Wednesday, April 11, 2012

Running selenium tests from visual studio

I was doing some testing using selenium, the way I was running tests at the beginning is through NUnit,  I thought to give it a try to use the visual studio to run the tests instead.

In visual studio 2010, I created a test project, added a new class file to it, named it selenium test

Added the basic test functions and attributes

the class attribute, and changed the class to be public

    [TestClass()]
public class SeleniumTest


Added Initialization and Cleanup methods



        [TestInitialize()]
public void MyTestInitialize()
{

}

[TestCleanup()]
public void MyTestCleanup()
{

}


Added my test method



        [TestMethod()]
public void TheApplyByQIDWebControlTest()
{

}


Next I took my initial cs file generated from Selenium IDE, opened it, mapped from NUnit functions to VS test functions, so code in [SetUp] went to [TestInitialize()] , code from [TearDown] went to [TestCleanup()] , code from [Test] went to the [TestMethod()]



I also added reference to selenium .NET dlls, built the project with no errors



Next I opened the Test View, my test method appeared in it, I clicked on run, the test started and I was able to run selenium test from visual studio

Wednesday, April 4, 2012

Exercise: Reversing characters per word in a string

I had an exercise to write a function to reverse characters per words in a string, so if I had a string like “I go to school every day” the output would be “I og ot loohcs yreve yad”

I solved this by 2 ways, one using arrays, and the other using stacks

        public static string ReverseWords(string s, char seperator)
{
if (s == null)
return "Arguments error";
Stack<char> wordAccumlator = new Stack<char>(); // stack to hold each word
Stack<char> textAccumlator = new Stack<char>(); //stack to hold the string after reversing words
for (int textIterator = s.Length-1; textIterator >= 0; textIterator--)
{
try
{
// push each character into the stack
wordAccumlator.Push(s[textIterator]);
// if charcter is the seperator, then start pushing the last word to the second stack
if (s[textIterator] == seperator)
{
wordAccumlator.Pop(); // to get ride of the sepertor character as we don't want to reverse it with the word
while (wordAccumlator.Count > 0)
textAccumlator.Push(wordAccumlator.Pop());
textAccumlator.Push(seperator); // add seperator after the word
}
else if (textIterator == 0) // at the end of the text, there is no seperator, but we need to push the last word
{
while (wordAccumlator.Count > 0)
textAccumlator.Push(wordAccumlator.Pop());
}

}
catch (Exception ex)
{
return "An error happened, " + ex.Message;
}
}
string result = string.Empty;
while (textAccumlator.Count > 0)
result = result + textAccumlator.Pop();
return result;
}

public static string ReverseWordsWithArray(string s, char seperator)
{
if (s == null)
return "Arguments error";
int length = s.Length;
char[] resultArray = new char[length];
int wordLength = 0; // counter for storing the last word length
for (int textIterator = 0; textIterator <= length; textIterator++)
{
try
{
// we will start processing the last word only if we see the seperator or this is the end of the string
if (textIterator == length || s[textIterator] == seperator)
{
// if this is the end of the string, we don't
if (textIterator < length)
resultArray[textIterator] = seperator;
for (int wordIterator = textIterator; wordIterator > textIterator - wordLength; wordIterator--)
{
//textIterator - wordLength represents the start location of the word
//(textIterator - wordIterator) represents a counter, 0, 1, 2 .. till wordLength
resultArray[textIterator - wordLength + (textIterator - wordIterator)] = s[wordIterator - 1];
}
wordLength = 0;
}
else
{
// we are still in the same word, increase word letters counter
wordLength = wordLength + 1;
}
}
catch (Exception ex)
{
return "An error happened, " + ex.Message;
}
}
string result = new string(resultArray);
return result;
}

Sunday, April 1, 2012

trac: bulk update for ticket custom field

We wanted to update a custom field for group of tickets in trac, we have version 0.11.6, tried to look around, and found that there is no support for bulk change from the UI

I thought of doing this on the DB directly, I found that our trac  is using SQLite from the configuration file,

database = sqlite:db/trac.db

I downloaded SQLiteStudio, a tool for SQLite from http://sqlitestudio.one.pl/

opened the tool, created new Database from the file stated above in the configuration file, usually it will be in trac-projects folder, inside project folder\db

started building my query, it ended up like below

update ticket_custom
set value = 'Parked'
where name = 'internal_status' and ticket in (select t.id from ticket t
    INNER JOIN ticket_custom tc on tc.ticket = t.id
where version in ('Release1','Release2')
     and tc.name = 'internal_status'
     and tc.value <> 'Closed' and tc.value <> 'Parked')

executing the above query, I was able to bulk update for my custom field for a group of tickets