Re: Weird behavior (M5)

From: Nick Stuart (nicholas.stuar..mail.com)
Date: Wed Aug 24 2005 - 17:52:28 EDT

  • Next message: Jeff de Vries: "Caching DataObjects from different DataContexts?"

    I understand, but just for re-assurance here is the whole test case as is:
    public void testCreate() {
            String name = "TestPage";
            String description = "This is an optional description.";
            
            IPageFactory pf = new PageFactory();
            ITemplateFactory tf = new TemplateFactory();
            
            CmsTemplate template = tf.create("TestPageTemplate", false, ctx);
            assertNotNull(template);
            tf.addBlock(template, "Block1PageCreate", ctx);
            tf.addBlock(template, "Block2PageCreate", ctx);
            assertEquals(2, template.getBlocks().size());
            
            CmsPage page = pf.create(template, name, description, ctx);
            assertNotNull(page);
            assertEquals(name, page.getName());
            assertEquals(description, page.getDescription());
            assertEquals(template, page.getTemplate());
            System.out.println("****** " + template.getBlocks().size() + "
    -- " + page.getBlocks().size());
            assertEquals(template.getBlocks().size(), page.getBlocks().size());
        }

    The ctx is initialized in the setup and no where else in the test. And
    I have stepped through the code and have watched the variables switch
    and copy when they are not supposed to.

    Right now I'm going to setup the stuff in the actual context of how it
    will be used (and not in an isolated test case) and hopefully things
    will work out. But this still bugs me that its doing this, but at the
    same time I'm not to worried cause this is just a milestone and not a
    final release.

    -Nick

    On 8/23/05, Kevin Menard <kmenar..ervprise.com> wrote:
    > Nick Stuart wrote:
    > > I know for sure that they all share the same DataContext as this is
    > > happening in a very small and simple unit test. The create method
    > > calls are taking place one right after the other. And the ctx is
    > > actually a static memeber that only gets initialized once for each
    > > run.
    >
    > Just as a personal anecdote, I was certain I was using the same
    > DataContext once, and it turned out I was not. What was happening was
    > that some objects were being pulled out of the DB with a different DC
    > and then added as part of a relationship to my objects of concern.
    > Well, if the objects of concern had not been registered with a DC yet,
    > they were auto-registered with the DC of the other objects added as part
    > of the relationship. I would then go ahead and register with my other
    > DC, which really wouldn't do anything since the objects were already
    > registered with a different DC. It wasn't until I actually debugged the
    > app that I realized what was going on.
    >
    > So, the moral of the story is that you can never be sure, even in the
    > simplest of examples. Btw, I managed to mess all of this up in about 5
    > lines of code.
    >
    > --
    > Kevin
    >



    This archive was generated by hypermail 2.0.0 : Wed Aug 24 2005 - 17:52:29 EDT