Archive for the ‘Development’ Category.

Tomcat multiple instances on Linux, Ubuntu / Mint

I was trying to figure out how to run multiple instances of Tomcat6 the other day on my Mint Linux. After a bit of searching and poking around I came to a very slick solution. But it took a while to find it, so I figure I will share the quick and dirty here, to get you up going quickly if your searching for the same.

Lets go through the whole thing, install Tomcat6
>sudo apt-get install tomcat6

You might have to set your java path if not set already, for example
>export JAVA_HOME=/usr/java/jdk1.6.0/bin/java
To check the setting
>echo $JAVA_HOME

You probably want to install the examples as well, just to mae sure things are working servlets, jsp etc,
>sudo apt-get install tomcat6-examples

If all is well as you would fully expect, you can start your Tomcat
>sudo sh /etc/init.d/tomcat6 start

And in return you will be able to access your tomcat in your browser at
http://localhost:8080

So lets take a look at how to configure multiple instances on the same linux box. Go to a directory where you want your new tomcat instance located. Then you do something like this
>tomcat6-instance-create myInstance

This will create a new directory called myInstance which will host your new instance of Tomcat. It will have it’s own configuration files, logs, etc. The first thing you probably want to do is to go to the config directory and change the ports in the server.xml file. Once you have the ports changed from the usual 8080 you can start your instance from /myInstance/bin directory.
>sh startup.sh

Just as you would with any other instance of Tomcat and shut down with the shutdown.sh script. Next time you need another instance on another port just create a new one
>tomcat6-instance-create myInstance_8030
and so on and so forth.

All the details can be found in the Ubuntu documentation.

Custom file extenstion in Visual Studio C#

I was using some files that have among other things some C# code in it in VS. When it dawned at me that I wasn’t getting the syntax highlighting which makes it much harder to read the code. Visual Studio just treats it as any other text file. In order to add a new one you just need to set new file association within VS. Tools – Options – Text editor – File Extensions. Add your extension and the editor you want to use, in my case Microsoft Visual C#. That will give you the code syntax, much better.

Code coverage from Nant script using Gallio and nCover

I decided to go with MbUnit for a new project, the newest version 3.x comes bundled with Gallio. Gallio is a test runner and can run loads of different flavors of tests. nUnit, msTest, MbUnit, etc. Of course once you have your tests running you wonder how much of your code gets coverage. To figure that one out I added NCover, here is a sample of how you can have nCover cover your Gallio UnitTest runs.

For best results install Gallio on the build machine and point to that directory when you load the task
loadtasks assembly=
also make sure your list of assemblies to be covered is just the assembly name, not the file name.
assembly.list=myAssembly1;myAssembly1;etc

<!– Gallio –>
<target name=“galliounittest”
              description=“Runs MbUnit UnitTests using Gallio.” >

<echo message=“*** Start Gallio unittest: “/>

<!– Run tests –>
<loadtasks assembly=“${path.gallio.task}Gallio.NAntTasks.dll” />

<gallio
  result-property=“exitCode”
  failonerror=“false”
  runner-type=“NCover”
  report-types=“Html;Xml”
  report-directory=“${artifacts}”
  report-name-format=“gallioresults”
  show-reports=“false”
  application-base-directory=“${path.base.test}”
  >

  <runner-property value=“NCoverArguments=’//w ${path.base.test} //a ${assembly.list}'” />
  <runner-property value=“NCoverCoverageFile=’${path.ncover.dir}${coverage.xml.file}'” />
  <!– Specify the tests assemblies  –>
  <files>
    <include name=“${path.base.test}${assembly.test}”/>
  </files>
</gallio>
<fail if=“${exitCode != ‘0’}” >One or more tests failed. Please check the log for more details</fail>

<echo message=“*** End Gallio unittest: “/>
</target>

<!– NCover –>
<target name=“nCoverReport”
              description=“Creates UnitTest Coverage report.” >

<echo message=“*** Start nCoverReport: “/>

    <ncoverexplorer
      program=“${path.ncover.explorer.exe}”
      projectName=“${PojectName}”
      reportType=“ModuleClassFunctionSummary”
      outputDir=“${path.ncover.dir}”
      xmlReportName=“${coverage.xml.file}”
      htmlReportName=“${coverage.html.file}”
      showExcluded=“false”
      verbose=“True”
      satisfactoryCoverage=“1”
      failCombinedMinimum=“true”
      minimumCoverage=“0.0”>

      <fileset>
        <include name=“${path.ncover.dir}${coverage.xml.file}” />
      </fileset>
      <exclusions>
        <exclusion type=“Assembly” pattern=“*.Tests” />
        <exclusion type=“Namespace” pattern=“*.Tests*” />
      </exclusions>
    </ncoverexplorer>

<echo message=“*** End nCoverReport: “/>
</target>

The solution was offline during its previous session and will remain offline

If your .Net solution gets disconnected from your Team Foundation Server you might get the following message once you load your solution in Visual Studio. “The solution was offline during its previous session and will remain offline.” in the Output window and your solution is kept offline. Which means your local changes are not picked up automatically and you will need to do manual checkouts and checkins into the repository for local files you have changed.

The trick is to manually reset the values in the registry, where else ?
HKEY_CURRENT_USER\Software\Microsoft\VisualStudio\9.0\TeamFoundation\Servers\ ( Your TFS server name )

set the values
AutoReconnect = 0
Offline = 0

Next time you open up your solution you will be asked if you want to connect to your Team Foundation Server, yes please.

Update…
If that does not work, try this one

Ant script, build Apache 2.2 and Mod_ssl

A friend of mine wanted to run the latest Aspache Mod_ssl available as some vulnerable holes have been patched in OpenSsl, but in order to do that you need to build it your self. Can you take a look he said, sure why not, he gave me a couple of links for instructions which is really all you need.

Instructions
Apachelounge
Devside

Source code(s)
OpenSsl
Apache
Zlib

Now I’m expecting my friend will need to do this again with another version in the future. So I figured why don’t we just create Ant script out of it. That way next time around we only need to change a couple of params about the source packages and we are off to the races. One click ant script should do the trick.

There are a couple of things that you have to have installed first on your system before you start. One is perl, I’m using ActivePerl but you should also be able to use other compatible perl packages. Another is awk, you might have to use gawk which you can then rename as awk on you computer before you start. Both of those need to be installed and available in the system path. I also have Vs2005 installed and that’s the one that will be used to do the compile. Also Zdll.lib was extracted from the Zlib binary as I got up against naming conflict on that one, put that one in \lib\zlib

Of course a simple Ant script to compile those would be impossible without the instructions mentioned before. And of course above all the people that put in the work to create the make files etc. Without them I would still be lost !

Here is the Ant script,

<project name=“nativeIndian” default=“ApacheBuild” basedir=“.”>

        <!–
    11/2009 – ORN
    ===
    – Apache –
    http://www.apachelounge.com/viewtopic.php?t=778
    http://www.devside.net/guides/windows/apache
    –
    http://www.openssl.org/source/
    http://httpd.apache.org/download.cgi
    http://www.zlib.net/

    ****
      Note –
      ActivePerl and Awk need to be present and available in the path.
      VS2005 is used to compile.
    ****

    This script will attempt the following
    ==========================================
    * Unzip sources
    * Set sources in place for compile
    * Compile OpenSsl
    * Test OpenSsl
    * Compile Apache
        –>

        <!– set global properties for this build –>
  <property name=“ApacheName” value=“Apache22” />
  <property name=“srcDir” location=“${basedir}/../” />
  <property name=“libDir” location=“${basedir}/../lib/” />
  <property name=“zipLibDir” location=“${basedir}/../lib/zlib/” />
  <!– Source –>
  <property name=“OpenSslTop” value=“openssl-0.9.8l” />
  <property name=“OpenSslSourceGz” location=“${basedir}/../${OpenSslTop}.tar.gz” />
  <property name=“OpenSslSourceTar” location=“${basedir}/../${OpenSslTop}.tar” />
  <property name=“ZlibTop” value=“zlib-1.2.3” />
  <property name=“ZlibSourceGz” location=“${basedir}/../${ZlibTop}.tar.gz” />
  <property name=“ZlibSourceTar” location=“${basedir}/../${ZlibTop}.tar” />
  <property name=“ApacheSourceTop” value=“httpd-2.2.14” />
  <property name=“ApacheSource” location=“${basedir}/../${ApacheSourceTop}-win32-src.zip” />
  <property name=“ApacheBin” value=“Apache_bin.zip” />
  <!– Build dirs–>
  <property name=“buildDir” location=“${basedir}/aphache/” />
  <property name=“buildLibDir” location=“${buildDir}/${ApacheSourceTop}/srclib/” />
  <property name=“buildLibZlibDir” location=“${buildDir}/${ApacheSourceTop}/srclib/zlib/” />
  <property name=“buildLibOpenSslDir” location=“${buildDir}/${ApacheSourceTop}/srclib/OpenSsl/” />

  <!– Hardcoded, VS2005 location –>
  <property name=“VsEnvir” location=“D:\apps\dev\Ide\vs2005\VC\vcvarsall.bat” />

  <!– TIMESTAMPS –>
        <tstamp>
                <format property=“TheStartTime” pattern=“dd-MM-yyyy hh:mm aa” />
        </tstamp>

 
  <!– DEFAULT RUN TARGETS  –>
  <target name=“ApacheBuild” depends=“startme,cleanUp,setup,compile,zipbin” >
    <echo message=“– Ending=${TheStartTime}” />
    <echo message=“– Done !” />
  </target>

 
  <!– Startup –>
  <target name=“startme” >
    <echo message=“– Start startme:” />
    <echo message=“– ${TheStartTime}” />
    <mkdir dir=“${buildDir}” />
  </target>

  <!– Fails on cleanup, as it might be clean already, or never created –>
        <target name=“cleanUp” >
    <echo message=“– Start cleanup:” />
                <delete dir=“${buildDir}” failonerror=“yes”/>
    <delete file=“${basedir}/${ApacheBin}” />
        </target>

  <!– Unzip and copy –>
  <target name=“setup” >
    <echo message=“– Start setup:” />
   
    <!– make sure the build dir is present –>
    <mkdir dir=“${buildDir}” />
   
    <!– Apache source –>
    <unzip src=“${ApacheSource}” dest=“${buildDir}”/>
   
    <!– OpenSsl source –>
    <gunzip src=“${OpenSslSourceGz}”/>
    <untar src=“${OpenSslSourceTar}” dest=“${buildDir}”/>
    <!– Add openssl to source dir –>
    <move todir=“${buildLibOpenSslDir}”>
      <fileset dir=“${buildDir}/${OpenSslTop}”/>
    </move>

    <!– Zlib source –>
    <gunzip src=“${ZlibSourceGz}”/>
    <untar src=“${ZlibSourceTar}” dest=“${buildDir}”/>
    <!– Add Zlib to source dir –>
    <move todir=“${buildLibZlibDir}”>
      <fileset dir=“${buildDir}/${ZlibTop}”/>
    </move>
    <!– Add zlib lib to source dir as well –>
    <copy file=“${zipLibDir}/zdll.lib” todir=“${buildLibZlibDir}”/>

  </target>
 
 
 
  <!– Compile packages  –>
  <target name=“compile” >
    <echo message=“– Start compile:” />

    <!– Vs2005 environment variables –>
    <exec executable=“cmd”>
      <arg value=“/c”/>
      <arg value=“${VsEnvir}”/>
    </exec>

    <!– Build OpenSsl –>
    <echo message=“– Start compile OpenSsl:” />
    <exec executable=“cmd” dir=“${buildLibOpenSslDir}” >
      <arg value=“/c”/>
      <arg value=“perl Configure VC-WIN32”/>
    </exec>
    <exec executable=“cmd” dir=“${buildLibOpenSslDir}”>
      <arg value=“/c”/>
      <arg value=“ms\do_masm”/>
    </exec>
    <exec executable=“cmd” dir=“${buildLibOpenSslDir}”>
      <arg value=“/c”/>
      <arg value=“nmake -f ms\ntdll.mak”/>
    </exec>
    <!– Test OpenSsl –>
    <echo message=“– Start test OpenSsl:” />
    <exec executable=“cmd” dir=“${buildLibOpenSslDir}/out32dll”>
      <arg value=“/c”/>
      <arg value=“..\ms\test”/>
    </exec>

   
    <!– Build Apache with the default localhost, port 80 –>
    <echo message=“– Start compile Apache:” />
    <exec executable=“cmd” dir=“${buildDir}/${ApacheSourceTop}”>
      <arg value=“/c”/>
      <arg value=“nmake /f Makefile.win SERVERNAME=localhost PORT=80 INSTDIR=${buildDir}/../${ApacheName} installr”/>
    </exec>

  </target>

  <!– Zip up the Apache  –>
  <target name=“zipbin” >
    <zip
      destfile=“${basedir}/${ApacheBin}”
      basedir=“${buildDir}/../${ApacheName}”
    />

  </target>

</project>

UnitTesting a door

I was explaining to somebody from non development world some time back what unittesting is about. At the time the best thing I could come up with was something along the way. Well if your building a house and then you install a door. Now you have to make sure the door works. In case of the door we write Unittest that makes sure that the door nob turns and does actually open the door. We also make sure that the door latches when it’s shut, further we make sure that the door fully opens and closes without any trouble. We make sure the key fits and can lock and unlock the door. Since we are at it we might as well shake the door and make sure nothing is rattling, that all screws were tightened up properly. Further if the door gets replaced it has to be verified that it works as well and the same key can be used as before.

The good part is once you have written the unittest it will work for the replacement door as well. This is where you get the most bang for you buck. Unless you never rewrite your software, that’s another story then. So let’s say your interior designer came up with a new door, a sliding door. Now your tests fail of course and they should, the function of the door has changed and it’s time to update the unittest. The base will stay the same the same key might still fit, the door should shut properly, etc. One of the new functions might be that the door slides open when a person walks into the sensor that triggers the door etc.

So how does it look when you need to unittest objects in your new webserver project. It’s similar but it’s a little different the problem is when you are running on a webserver you are running in a container. The container is the webserver. So logically you can’t test the door as the door can only be accessed when inside the container ( installed in the house ). The problem with that is that you do not want to unittest against a live webserver. As you can not get down to the object level to address the door directly. Therefor the trick is to setup a unittest environment that can fake the container / house. Once you do that your door thinks that it’s installed in a house and you can verify that the door functions as expected.

There is only one thing left to say, Jawoll Mein Agile F├╝hrer