<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    2006年7月5日

    Install Oracle 11g R2 on Ubuntu

    Ubuntu is not an official supported linux version from Oracle, so I still get some errors during the install process even with required configuration, anyway, it can work and what i'm doing here is try to setup an experiment environment, it's enough to me, any one who want to deploy Oracle in product mode should have supported linux platform like RedHat, OK, following is the steps i have to install it:

    1. If you were in multihomed enviroment, set the ORACLE_HOSTNAME variable:
        export ORACLE_HOSTNAME=machine_name.domain_name

    2. Create create OSDBA (dba) group, Oracle Inventory group (oinstall)  and a user "oracle" which has "dba" as its login group and oinstall as its 2nd group.

    3. Modify /etc/sysctl.conf, set kernel parameter:

    kernel.shmall = 2097152
    kernel
    .shmmax = 2147483648
    kernel
    .shmmni = 4096
    kernel
    .sem = 250 32000 100 128
    fs
    .file-max = 65536
    net
    .ipv4.ip_local_port_range = 1024 65000
    net
    .core.rmem_default = 1048576
    net
    .core.rmem_max = 1048576
    net
    .core.wmem_default = 262144
    net
    .core.wmem_max = 262144

    4. Modify /etc/security/limits.conf to improve the "number of process" and "number of open file"  performance for oracle:
    oracle              soft    nproc   2047
    oracle              hard    nproc   
    16384
    oracle              soft    nofile  
    1024
    oracle              hard    nofile  
    65536

    5. Modify /etc/pam.d/login, add:
    session    required     /lib/security/pam_limits.so
    session    required     pam_limits
    .so

    6. Modify /etc/profile:
    if [ $USER = "oracle" ]; then
            
    if [ $SHELL = "/bin/ksh" ]; then
                  ulimit 
    -16384
                  ulimit 
    -65536
            
    else
                  ulimit 
    -16384 -65536
            fi
    fi

    7. Change user to oracle if you haven't done it yet

    8. Create base directory, for me it's "/app/oracle"

    9. Export ORACLE_BASE, ORACLE_SID
    export ORACLE_BASE=/app/oracle
    export ORACLE_SID
    =orcl

    10.  If you're trying to install oracle with a X window:
    DISPLAY=your.ip.address:0.0 ; export DISPLAY

    11. run installer:
    ./runInstaller

    12. Oracle should start, if the installer GUI cannot be start, check the error messages, most time it's because a wrong X window configuration, if you are running X window with Xming, just like me, please do make sure to check the "No Access Control" check box in the launch, otherwise, Xming will reject the connection.

    13. Now the GUI shoudl open, like what you did in the Windows system, fullfill required value and click next, ingore all errors if there is any condition that is not match, click finish in the last step, it should start install process.

    14. After install oracle, the installer GUI will ask you to run two .sh files, run it with a root role.

    15. You can try to visit https://you.ip.address:1158/em to see is that OK for you.

    16. How to start oracle:
    export ORACLE_BASE=/app/oracle
    export ORACLE_HOME
    =/app/oracle/product/11.2.0/dbhome_1
    export ORACLE_OWNR
    =oracle
    export ORACLE_SID
    =orcl
    export PATH
    =$PATH:$ORACLE_HOME/bin


    lsnrctl start

    sqlplus 
    /nolog
    connect /as sysdba
    startup
    quit

    emctl start dbconsole


    Reference
    http://download.oracle.com/docs/cd/B19306_01/install.102/b15660/pre_install.htm#BABDFJAE

    posted @ 2010-03-16 15:57 Find it, try it, experience it 閱讀(596) | 評(píng)論 (0)編輯 收藏

    How to connect Reliance Modem AC2726 on Linux Ubuntu 9.10

    1. Type command: lsusb
    Bus 002 Device 003: ID 19d2:fff5 ONDA Communication S.p.A.
    2. Install "usb-modeswitch", then re-plugin modem again and input command "lsusb" again, you should get the following output
    Bus 002 Device 003: ID 19d2:fff1 ONDA Communication S.p.A.
    3. Notice in step #2, the product code has been changed from "fff5" to "fff1".
    4. Install package "wvdial" which is used to dail up
    5. Type command: "sudo modprobe usbserial vendor=0x19d2 product=0xfff1", don't forget the "sudo"
    6. Type command: "sudo wvdialconf", again don't forget the "sudo", this will detect your modem
    7. Modify file "/etc/wvdial.conf", following is what I have:

    [Dialer Defaults]
    Init1 
    = ATZ
    Init2 
    = ATQ0 V1 E1 S0=0 &C1 &D2 +FCLASS=0
    Modem Type 
    = Analog Modem
    ISDN 
    = 0
    New PPPD 
    = 1
    Phone 
    = #777
    Modem = /dev/ttyUSB0
    Username 
    = yourName
    Password 
    = yourPassword
    Baud 
    = 921600
    Stupid Mode 
    = 1
    Tonline 
    = 0

    8. Repeat step #5 again and then if you with not bad luck type in command "sudo wvdial", you should connect in.
    9. If bad luck with you, click right-upper corner, there is a connection configuration menu, you can create "Mobile Broadband" connection yourself here, don't forget input the phone number "#777" (for China Telcom) and your username password, after that click connect, this works for me.
    10. Good luck with you.
    11. BTW, if it still cannot work, try to re-plug in the modem.

    posted @ 2010-03-12 18:03 Find it, try it, experience it 閱讀(399) | 評(píng)論 (0)編輯 收藏

    Oracle Tips Part Two

    1. It will not get data from DB when just open the cursor, data will be loaded as an ongoing basis.

    2. SCN: System Change Number/System Commit Number

    3. FLASH BACK AS OF SCN;

    4. You can also flash back table: FLASHBACK TABLE SOME_TABLE TO SCN :SCN_NUM;

    5. But before you do a flash back operation on a table, do make sure you have already enbale ROW MOVEMENT on that table.

    posted @ 2010-03-07 18:03 Find it, try it, experience it 閱讀(181) | 評(píng)論 (0)編輯 收藏

    Oracle Tips One

    1. Do use oracle "Bind variable", it can increase the speed by 90 percent in 10g release1.

    2. Understand how to use "lock", read never block write,  vice verse.

    3. There is a side effect from oracle regarding to the "lock", if you do want to control the access to one row at a specify time (like doing an if 'this row belong to some search condition' then 'modify this row' action), you have to write some logic yourself, for example use the "for update" statement, like: "select * from x where x.id = 1 for update", so that you can lock the row only with id equals to '1' and then modify this row, so that some orther concurrence requests should execute the same sql first, yes, with the same 'for update' statement, and because you already have locked this row(id = 1), orther requests cannot get the access to it, and you get the access control to this row.

    4. Regardint to item 3, it will not decrease the concurrence level, because first you only lock the item with id equals to 1 and there maybe thousands of items in your table, second, it will not block the read request.

    posted @ 2010-03-06 21:25 Find it, try it, experience it 閱讀(230) | 評(píng)論 (0)編輯 收藏

    算法求解!如何判斷一個(gè)單向鏈表是否有環(huán)路?

    這該死的問(wèn)題讓我竟然沒(méi)有想到解決方案...腦子生銹了?呵呵,算了...

    該問(wèn)題最經(jīng)典的解答,簡(jiǎn)直是一句話(huà)驚醒夢(mèng)中人啊

    “用兩個(gè)指針,一個(gè)的步長(zhǎng)為 1,另外一個(gè)的為 2,從表頭開(kāi)始一起往前走,如果相遇,表明有環(huán)路,否則就是沒(méi)有了。”

    下來(lái),不用說(shuō)什么了吧,用JAVA實(shí)現(xiàn)的話(huà),聲明兩個(gè)Iterator A 和 B,A 每次調(diào)用兩個(gè)NEXT,B只調(diào)用一次,如果他們能夠相遇,就是有環(huán)...我操

    posted @ 2009-03-02 14:15 Find it, try it, experience it 閱讀(630) | 評(píng)論 (0)編輯 收藏

    Something you may ingore when to use Hibernate and JPA.

    The first is about identity generator, this is something I ingored and find really interesting later when I read back the document.

        When you choose "native" (for plain hibernate) or "AUTO" (for JPA which use hibernate as provider) as identity generator, it (actually they are the same identity generator but with different name in different scope) will pick other identity generators like identity, sequence, or hilo, depending on the capabilities of the underlying database. Use this generator to keep your mapping metadata portable to different database management systems.
        If your underlying DB is oracle, it will automatically create a sequence for you which means choose the sequence as identity generator, that's really interesting, at least for me for the first time when it comes to me.

    The second is about the flush and close session operations when to use hibernate with JTA transaction.

        You should manually flush your operation by call flush method and close your session by calling close method when you try to use JTA transaction instead of hibernate Transaction API, these is because hibernate Transaction API does thoes operations automatically for you. But, with following configuration, it can also be done automatically for you by hibernate, though you are still with JTA transaction.

        hibernate.transaction.flush_before_completion=true
        hibernate.transaction.auto_close_session=true

    The third is about an interesting code snatch listed as follow:
       
    1     Session session = sessionFactory.openSession();
    2     session.beginTransaction();
    3     session.save(new Item());
    4     session.close();

        What happen if you don't commit the transaction? It's depends on the underlying DB, for oracle it will commit any uncommited transactions, but for many other DB vendors, they will roll back any pending transactions.
       

    posted @ 2008-04-03 16:32 Find it, try it, experience it 閱讀(918) | 評(píng)論 (0)編輯 收藏

    A "Hello" program on EJB3 with Jboss server 4.2.2GA (PART 3) - EJB3 Timer service.

        Timer service in EJB3 with anotation is fairly simple, I give you an example as follow, and it's really simple and self-explanation:
     1 package com.ramon.expejb3.session.impl;
     2 
     3 import javax.annotation.Resource;
     4 import javax.ejb.Stateless;
     5 import javax.ejb.Timeout;
     6 import javax.ejb.Timer;
     7 import javax.ejb.TimerService;
     8 
     9 import com.ramon.expejb3.session.Greeting;
    10 
    11 @Stateless(name = "Greeting")
    12 public class GreetingBean implements Greeting {
    13     
    14     @Resource
    15     TimerService ts;
    16 
    17     /* (non-Javadoc)
    18      * @see com.ramon.expejb3.session.Greeting#greeting(java.lang.String)
    19      */
    20     public void greeting(String name) {
    21         System.out.println("Hello " + name + ".");
    22         ts.createTimer(1 * 10005 * 1000, name);
    23         System.out.println("Create timer for " + name + ".");
    24     }
    25     
    26     @Timeout
    27     public void timeout(Timer timer) {
    28         String name = (String)timer.getInfo();
    29         System.out.println(name + " TIME OUT.");
    30         //timer.cancel();
    31     }
    32 }
    33
        It's the "GreetingBean" I introduced in part one of this series article with TimerService injected, @Resource anotation inject the time service we want, it's totally free which is supported by the J2EE container that means we do not need any further steps to get the powerful schedule service. In the line 22, I crate a new timer, I think this could be more fit if it was called Task instead, there are several "createTimer" methods with different parameters, the one I used here describe the task should be execute 1 second delay and every 5 second one time in the future, the third parameter can be anything you want to pass in to the task, it can be get back use method Timer.getInfo() like line 28 does here.
        Another important anotation here is the @Timeout anotation, this anotation tell container which method will be called when timeout for this task to be executed, you can only specify one timeout method for each Bean, if there is no @Timeout anotation at all, you will get some exception like "No timeout method specified" in Jboss server. Something funny here is that you should mark the timeout method as "public", otherwise, you will get the same error as no timeout method does, I do NOT think it's necessary, because the time out method should only be called by the container, "private" signature is enought for that, with "private" signature container still has the right to access this method with java reflection, nevertheless timer service in EJB3 is still a good tools for use.
        I summarize what good/bad for timer service in EJB3 as follow:
        Good news:
    •     It's free, it's supported by the EJB container.
    •     It's portable, it's supported by the EJB container as specified in EJB3 specification.
    •     It's easy to use, no need to learn more.
        Bad news:
    •     The feature of EJB3 timer sevice is not as powerful as some third party timer service such as Quartz, but it's enough with EJB3 for ordinary daily job.
    •     There is no UI for you to monitor the timer you created.

    posted @ 2008-03-26 13:30 Find it, try it, experience it 閱讀(1181) | 評(píng)論 (0)編輯 收藏

    A "Hello" program on EJB3 with Jboss server 4.2.2GA (PART 2) - EJB3 MDB with Jboss server.

         摘要:     MDB is the MVP(most valuable player) both in previous EJB version and EJB3. Although coding with MDB is simple in EJB2.x, EJB3 make it much more friendly to you. Let's get to the ...  閱讀全文

    posted @ 2008-03-25 17:42 Find it, try it, experience it 閱讀(1124) | 評(píng)論 (0)編輯 收藏

    A "Hello" program on EJB3 with Jboss server 4.2.2GA.

        Recently I did some research on EJB3 programming, find that it's really simple than programming with previous EJB version. Coding in EJB2.X or previous version is really a nightmare for most developers, maybe for this, EJB3 gives me much more impression than Spring when it first comes to me, this article is the first one of these series articles which record the new knowledge I find interesting in EJB3.

        Well, let's begin.

        EJB3 is simple with AOP and DI, there is no Home interface any more, only with Service Interface and your Service implementation you can create an typical EJB3 application. I will create a simple hello world program in this article, the service interface as follow:

     1 package com.ramon.expejb3.session;
     2 
     3 import javax.ejb.Remote;
     4 
     5 @Remote
     6 public interface Greeting {
     7     
     8     /**
     9      * say hello test
    10      * @param name
    11      */
    12     void greeting(String name);
    13 
    14 }

        It's really simple, especially for you that are familiar with programing with Interface, after that is the service implementation code:
     1 package com.ramon.expejb3.session.impl;
     2 
     3 import javax.annotation.PostConstruct;
     4 import javax.annotation.PreDestroy;
     5 import javax.ejb.Stateless;
     6 
     7 import com.ramon.expejb3.session.Greeting;
     8 
     9 @Stateless(name = "Greeting")
    10 public class GreetingBean implements Greeting {
    11     
    12     @PostConstruct
    13     public void init() {
    14         System.out.println("Init Greeting Bean.");
    15     }
    16     
    17     @PreDestroy
    18     public void destroy() {
    19         System.out.println("Garbage collect Greeting Bean.");
    20     }
    21 
    22     /* (non-Javadoc)
    23      * @see com.ramon.expejb3.session.Greeting#greeting(java.lang.String)
    24      */
    25     public void greeting(String name) {
    26         System.out.println("Hello " + name + ".");
    27     }
    28 }
    29 
        Still simple and very self-explanation, @Stateless(name = "Greeting") specify the JNDI name for client invocation. OK, that's all for our EJB jar file, no more file needed for this simple hello application. Execute your ANT script make a jar for it, part of ANT script may look like:
     1     <target name="prepareexpejb3" description="Create exp_jsf distribution.">
     2         <mkdir dir="${dist.dir}" />
     3         <mkdir dir="${build.dir}" />
     4         <mkdir dir="${build.core.dir}"/>
     5     </target>
     6 
     7     <!-- ================================= 
     8           target: Compile expejb3 classes      
     9          ================================= -->
    10     <target name="compileexpejb3" depends="cleanDist,prepareexpejb3">
    11         <javac destdir="${build.core.dir}" debug="yes" deprecation="on" srcdir="${src.dir}">
    12             <include name="${core.src.dir}/**" />
    13             <classpath refid="expejb3.classpath" />
    14         </javac>
    15         
    16     </target>
    17 
    18     <!-- ================================= 
    19           target: Create EJB3 jar
    20          ================================= -->
    21     <target name="createEJB3Jar" depends="compileexpejb3">
    22         <jar jarfile="${dist.dir}/${expejb3.core.name}.jar">
    23             <fileset dir="${build.core.dir}"></fileset>
    24         </jar>
    25     </target>

        Put the EJB jar into jboss server server\default\deploy, you should see some log from jboss console like:
       
    1 10:59:27,036 INFO  [JmxKernelAbstraction] creating wrapper delegate for: org.jboss.ejb3.stateless.St
    2 atelessContainer
    3 10:59:27,051 INFO  [JmxKernelAbstraction] installing MBean: jboss.j2ee:jar=expejb3core.jar,name=Gree
    4 ting,service=EJB3 with dependencies:
    5 10:59:27,208 INFO  [EJBContainer] STARTED EJB: com.ramon.expejb3.session.impl.GreetingBean ejbName:
    6 Greeting
        Which mean that you have successfully deploy your EJB into jboss server, create a client code to invoke your EJB service:
     1 package com.ramon.expejb3.session;
     2 
     3 import java.util.Properties;
     4 
     5 import javax.naming.Context;
     6 import javax.naming.InitialContext;
     7 
     8 import junit.framework.TestCase;
     9 
    10 public class ExpEJB3BaseTestCase extends TestCase {
    11 
    12     private Properties properties = null;
    13     
    14     private Context context;
    15 
    16     protected void setUp() throws Exception {
    17         super.setUp();
    18         properties = new Properties();
    19         properties.put("java.naming.factory.initial""org.jnp.interfaces.NamingContextFactory");
    20         properties.put("java.naming.factory.url.pkgs""org.jboss.naming:org.jnp.interfaces");
    21         properties.put("java.naming.provider.url""localhost:1099");
    22         context = new InitialContext(properties);
    23     }
    24 
    25     protected void tearDown() throws Exception {
    26         super.tearDown();
    27         context = null;
    28         properties = null;
    29     }
    30 
    31     public final Context getContext() {
    32         return context;
    33     }
    34 
    35     public final void setContext(Context context) {
    36         this.context = context;
    37     }
    38 
    39 }
    40 

     1 package com.ramon.expejb3.session.impl;
     2 
     3 import javax.naming.NamingException;
     4 
     5 import com.ramon.expejb3.session.ExpEJB3BaseTestCase;
     6 import com.ramon.expejb3.session.Greeting;
     7 
     8 public class GreetingBeanTest extends ExpEJB3BaseTestCase {
     9 
    10     public void testGreeting() {
    11         try {
    12             Greeting greetService = (Greeting)this.getContext().lookup("Greeting/remote");
    13             greetService.greeting("Ramon");
    14         } catch (NamingException e) {
    15             // TODO Auto-generated catch block
    16             e.printStackTrace();
    17         }
    18     }
    19 
    20 }
    21 
        That's really simple, right? What you should note is that you must include following jars into your classpath when you run this clien test case, otherwise you will get the annoying classNotFound Exception:
     1 concurrent.jar
     2 jboss-aop-jdk50.jar
     3 jboss-aspect-library-jdk50.jar
     4 jboss-common.jar
     5 jboss-ejb3.jar
     6 jboss-ejb3-client.jar
     7 jboss-remoting.jar
     8 jbossx-client.jar
     9 jboss-transaction-client.jar
    10 jnp-client.jar


     

       

    posted @ 2008-03-21 16:02 Find it, try it, experience it 閱讀(1807) | 評(píng)論 (0)編輯 收藏

    編碼字符集與Java -Java World亂碼問(wèn)題根源之所在。

         摘要: 本文介紹了編碼字符集的概念以及Java與編碼字符集之間的關(guān)系,文章的內(nèi)容來(lái)自于本人工作過(guò)程中的經(jīng)驗(yàn)積累以及網(wǎng)絡(luò)中的相關(guān)文章介紹,如果文章中有任何紕漏歡迎讀者指正,讓我們共同討論學(xué)習(xí)J1.????? 字符字符是抽象的最小文本單位。它沒(méi)有固定的形狀(可能是一個(gè)字形),而且沒(méi)有值。“A”是一個(gè)字符,“€”(德國(guó)、法國(guó)和許多其他歐洲國(guó)家通用貨幣的標(biāo)志)也是一個(gè)字符?!爸小薄皣?guó)”這是兩個(gè)漢字字符。字符僅僅代...  閱讀全文

    posted @ 2006-09-24 00:08 Find it, try it, experience it 閱讀(9361) | 評(píng)論 (5)編輯 收藏

    計(jì)算機(jī)中[1]和[-1]的趣事.

    首先感謝南老師!

    ??????在計(jì)算機(jī)里的有符號(hào)數(shù),最高位的1用來(lái)表示負(fù)號(hào),所以,用 0000 0001表示正1,1000 0001表示-1,確實(shí)對(duì)人來(lái)說(shuō)很直觀。但其實(shí),計(jì)算機(jī)里的數(shù)是用“補(bǔ)碼”表示的。其中正數(shù)的補(bǔ)碼就是原來(lái)的數(shù)(稱(chēng)為原碼),而負(fù)數(shù)的補(bǔ)碼是這么算的,我用倒推的來(lái)說(shuō):
    ??????補(bǔ)碼 = 反碼 + 1
    ??????反碼 = 原碼按位取反(1變0,0變1)
    ??????所以,-1就是1取補(bǔ)碼,過(guò)程如下:
    ??????先取反 0000 0001 ---> 1111 1110?
    ??????然后加1得補(bǔ)碼: 1111 1110 + 1 = 1111 1111?
    ????(當(dāng)然這里為了方便,就取了8位,其實(shí)整數(shù)現(xiàn)在都是32位了,結(jié)果是32個(gè)1)。

    ?????現(xiàn)在,你知道如何計(jì)算-2了嗎? 為什么要搞反碼,補(bǔ)碼這么個(gè)轉(zhuǎn)換呢? 這個(gè)原因要說(shuō)長(zhǎng)就很長(zhǎng)的,但簡(jiǎn)單地講,這又是一個(gè)在人的直觀和機(jī)器的高效之間取一個(gè)平衡:
    ?????我們先來(lái)看一個(gè)10進(jìn)制的數(shù)運(yùn)算:
    ?????1 + (-1) = 0 //10進(jìn)制中,1加負(fù)1應(yīng)為0.
    ?????然后,假如用1000 0001來(lái)表示-1的話(huà)。按照計(jì)算機(jī)計(jì)算加法的規(guī)則,它是每位加的,結(jié)果是:
    ?????0000 0001 + 1000 0001 = 1000 0010??//-2
    ?????結(jié)果變成-2了,其中后面兩個(gè)0001 相加變成2,而前面的用于表示負(fù)號(hào)的1,被“繼承”下來(lái)了……顯然,原來(lái)計(jì)算機(jī)最直觀的(對(duì)人來(lái)說(shuō)也很直觀的)算法,不靈了!怎么辦?痛苦

    ??? 但更痛苦的事還在0這個(gè)數(shù)上。按10進(jìn)制,0和-0可是完全相等的。但如果用二進(jìn)制,0000 0000 和 1000 0000 參加起運(yùn)算,可是完全不同?;蛟S可以通過(guò)電路設(shè)計(jì),來(lái)強(qiáng)制讓計(jì)算機(jī)去實(shí)現(xiàn)一個(gè)規(guī)則: 碰到1000 0000就先轉(zhuǎn)換為0000 0000。但可要知道加減法計(jì)算是計(jì)算機(jī)計(jì)算一切的基礎(chǔ),如果從這最底層就必須有一個(gè)轉(zhuǎn)換會(huì)極大影響性能!何況前面那個(gè)問(wèn)題也必須有個(gè)強(qiáng)制規(guī)則!規(guī)則最好越簡(jiǎn)單越好,那就是規(guī)定前面的補(bǔ)碼轉(zhuǎn)換規(guī)則,這個(gè)轉(zhuǎn)換過(guò)程對(duì)于計(jì)算機(jī)來(lái)說(shuō)很迅速的邏輯電路轉(zhuǎn)換。

    ??? 你看,第一個(gè)問(wèn)題 1 + (-1)
    ? ? 0000 0001 + 1111 1111 = 0000 0000?
    ????看明白這個(gè)計(jì)算過(guò)程嗎?其實(shí)就是最低位的兩個(gè)1相加后,造成每一位都進(jìn)位,最高位直接溢出(丟了)。如果你還算不清,就算算這個(gè)10進(jìn)制的:
    ????1 + 999 =??1000 (最高位1丟失,就成0了)
    ????然后是第二個(gè)問(wèn)題,0的表示。如果您把0當(dāng)成正數(shù),那么它是這樣表示的:
    ????0000 0000
    ????如果你當(dāng)它是負(fù)數(shù),那么
    ????取反 1111 1111 ,再加1,以求補(bǔ) ,哈哈又成 0000 0000這回在邏輯上沒(méi)有錯(cuò)誤了!明白了吧?當(dāng)補(bǔ)我在學(xué)習(xí)這一段知識(shí)時(shí),只能說(shuō):高,實(shí)在高! 想出補(bǔ)碼的前輩,真是高人啊。

    posted @ 2006-09-20 20:59 Find it, try it, experience it 閱讀(242) | 評(píng)論 (0)編輯 收藏

    Unit Testing against Struts action(Controller in MVC), In-Container or Mock Objects which One Should We Choose?

    This article is focused on which approach we should choose for unit testing against Struts action, I hope it will give you some help when you have question on how to do unit testing against the controller in MVC.

    OK, let's begin!

    In container? Mock objects?

    There are two kinds of testing, one is in-container and the other is do testing with mock objects. Generally speaking, it was considered to be more really and truly unit testing when you do testing with mock objects, especially when you do testing against java source files which should be run in J2EE container, but as our code become complex which contain more layers, the controller(Struts) will have more depends on the other layer which may be EJB service or other business objects, so when you do unit testing against view layer(here is Struts), it will be a huge work for you to construct the mock objects and also it will have more source code changed as you apply mock objects in your source code, the following is a simply description which describe the classic three layers project, and also considerd to be the most common type of web based project.

    e.g. the Struts action class first call the EJB factory to get an EJB service, and then ask this EJB service to do the work according to the business logic and return the value we need, with the value EJB service returned the action class can choose which page to redirect or do some other data processing ,this could be the classic three layers type, maybe the most common type project we used in our project.

    Therefore, it may not be the best choice for every web based project to apply mock objects unit testing. In the case that Struts action class is close tied with your business object, in-container testing may be an alternate choice for you, because it save your time to write mock objects and the workload to apply the mock objects into your source files but supply the same testing resluts.

    In-container testing sounds good, but when you do testing in this style, it first assume that the depended business service classes used in our Struts action must be verified, if the depended service classes have some defect that happen to be met when we run in-container testing, it will take more time to find which cause the error indeed.

    But I think if we have a complete testing procedure, which cover the service layer and the controller, the service layer have already been verified properly, in-container testing is really the best choice for you to use for testing action class. For project in practice, the Struts action is more or less close tied with other layer, it's not realistic to spend more time on writing mock objects or modifying your source code to apply the mock objects. In my opinion, the recommended solution is that you should focus on Struts layer testing, if the Struts action code is close tied with other service layer which I mean is that there may be only one execute() method in every Struts action take charge for the whole business logic, you should use in-container testing, let other unit testing stuff take charge for service layer which may be out of container unit testing against EJB, in this way you can write your test case at your pleasure, forget the depended layers for a while, the container will take care for other layers for you, and also it will save you lots of time for writing mock objects, the container will give you the real objects instead of mock objects.Mock object testing is more often used for the simple Struts action or the case that it could be influenced by the container when you do unit testing against Struts action.

    posted @ 2006-07-06 23:11 Find it, try it, experience it 閱讀(1102) | 評(píng)論 (0)編輯 收藏

    Wow~~ It will be a new beginning for me!

    I will write some thing?when I have time tomorrow, sorry, it's already 1:00 AM at midnight, so you guys?could see some thing right now, hey hey. It's mainly about how to automatic do unit testing in container with strutstestcase and ANT, hope it will be useful for you guys.

    posted @ 2006-07-05 01:06 Find it, try it, experience it 閱讀(168) | 評(píng)論 (0)編輯 收藏

    <2006年7月>
    2526272829301
    2345678
    9101112131415
    16171819202122
    23242526272829
    303112345

    導(dǎo)航

    統(tǒng)計(jì)

    公告

    If there is any question you have, please don't hesitate, let me know ASAP, you can find me at kenees@gmail.com or QQ: 9808873, hope to make friends with you ;)

    常用鏈接

    留言簿(1)

    隨筆檔案

    文章檔案

    搜索

    積分與排名

    最新評(píng)論

    閱讀排行榜

    評(píng)論排行榜

    主站蜘蛛池模板: 国产99精品一区二区三区免费 | 亚洲乱码国产一区网址| 日韩中文字幕精品免费一区| 国产精品内射视频免费| 久久久久高潮毛片免费全部播放| 日本免费中文字幕| 精品一区二区三区高清免费观看| 国产99精品一区二区三区免费 | 女人18一级毛片免费观看| 天天影视色香欲综合免费| 亚在线观看免费视频入口| 免费不卡在线观看AV| 2021在线永久免费视频| 成熟女人特级毛片www免费| 免费无码又爽又刺激高潮| 日韩在线免费电影| 免费夜色污私人影院在线观看| 又大又粗又爽a级毛片免费看| 91在线亚洲精品专区| 精品亚洲成a人片在线观看| 97亚洲熟妇自偷自拍另类图片| 亚洲经典千人经典日产| 亚洲av无码专区在线观看下载| 亚洲av成本人无码网站| 日韩精品无码一区二区三区免费 | 亚洲日日做天天做日日谢| 亚洲人成毛片线播放| 国产精品亚洲综合久久| 99久久成人国产精品免费| 免费无码又爽又刺激高潮软件| 亚洲免费福利视频| 亚洲人色婷婷成人网站在线观看| 亚洲AV永久青草无码精品| 亚洲高清美女一区二区三区| 特级毛片爽www免费版| a毛片久久免费观看| 全部免费国产潢色一级| 亚洲AV无码国产丝袜在线观看| 日本免费精品一区二区三区 | 久久午夜伦鲁片免费无码| 亚洲黄片手机免费观看|