hivemind-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hls...@apache.org
Subject cvs commit: jakarta-hivemind/framework/src/conf log4j.properties
Date Fri, 13 Aug 2004 13:19:15 GMT
hlship      2004/08/13 06:19:15

  Modified:    framework/src/conf log4j.properties
  Added:       framework/src/test/org/apache/hivemind/impl
                        TestServiceModelThreading.java StandardWorker.java
                        Worker.java ThreadedWorker.java
                        ServiceModelThreading.xml PooledWorker.java
  Log:
  HIVEMIND-44: Add tests to verify that the service models work under high threading loads.
  
  Revision  Changes    Path
  1.1                  jakarta-hivemind/framework/src/test/org/apache/hivemind/impl/TestServiceModelThreading.java
  
  Index: TestServiceModelThreading.java
  ===================================================================
  //  Copyright 2004 The Apache Software Foundation
  //
  // Licensed under the Apache License, Version 2.0 (the "License");
  // you may not use this file except in compliance with the License.
  // You may obtain a copy of the License at
  //
  //     http://www.apache.org/licenses/LICENSE-2.0
  //
  // Unless required by applicable law or agreed to in writing, software
  // distributed under the License is distributed on an "AS IS" BASIS,
  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  // See the License for the specific language governing permissions and
  // limitations under the License.
  
  package org.apache.hivemind.impl;
  
  import org.apache.hivemind.Registry;
  import org.apache.hivemind.test.HiveMindTestCase;
  
  /**
   * Tests to verify that the service models work properly even under high-thread count
   * concurrent stress.
   *
   * @author Howard Lewis Ship
   */
  public class TestServiceModelThreading extends HiveMindTestCase
  {
      public static final int THREAD_COUNT = 20;
      public static final int ITERATIONS = 10;
      public static final long JOIN_WAIT = 500;
  
      private static class RunnableFixture implements Runnable
      {
          private int _invokeCount = 0;
  
          public int getInvokeCount()
          {
              return _invokeCount;
          }
  
          // ++ is atomic, so no need to synchronize 
  
          public void run()
          {
              _invokeCount++;
          }
      }
  
      private static class RunnableManager implements Runnable
      {
          private Registry _registry;
          private Worker _worker;
          private Runnable _runnable;
          private boolean _completed = false;
  
          private RunnableManager(Registry registry, Worker worker, Runnable runnable)
          {
              _registry = registry;
              _worker = worker;
              _runnable = runnable;
          }
  
          public void run()
          {
              for (int i = 0; i < ITERATIONS; i++)
              {
                  _worker.run(_runnable);
  
                  _registry.cleanupThread();
              }
  
              _completed = true;
          }
  
          public boolean getCompleted()
          {
              return _completed;
          }
      }
  
      private void execute(String serviceId) throws Exception
      {
          Registry r = buildFrameworkRegistry("ServiceModelThreading.xml");
  
          Worker w = (Worker) r.getService(serviceId, Worker.class);
  
          Thread threads[] = new Thread[THREAD_COUNT];
          RunnableManager managers[] = new RunnableManager[THREAD_COUNT];
  
          RunnableFixture fixture = new RunnableFixture();
  
          for (int i = 0; i < THREAD_COUNT; i++)
          {
              managers[i] = new RunnableManager(r, w, fixture);
  
              threads[i] = new Thread(managers[i], "Worker #" + (i + 1));
          }
  
          for (int i = 0; i < THREAD_COUNT; i++)
              threads[i].start();
  
          // Let the rest do their thing
  
          Thread.yield();
  
          for (int i = 0; i < THREAD_COUNT; i++)
          {
              try
              {
                  threads[i].join(JOIN_WAIT);
              }
              catch (InterruptedException ex)
              {
              }
          }
  
          assertEquals(
              "Number of executions of the RunnableFixture",
              THREAD_COUNT * ITERATIONS,
              fixture.getInvokeCount());
      }
  
      public void testPrimitive() throws Exception
      {
          execute("hivemind.test.threading.PrimitiveWorker");
      }
      
      public void testSingleton() throws Exception
      {
      	execute("hivemind.test.threading.SingletonWorker");
      }
      
      public void testThreaded() throws Exception
      {
      	execute("hivemind.test.threading.ThreadedWorker");
      }
      
      public void testPooled() throws Exception
      {
      	execute("hivemind.test.threading.PooledWorker");
      }
  }
  
  
  
  1.1                  jakarta-hivemind/framework/src/test/org/apache/hivemind/impl/StandardWorker.java
  
  Index: StandardWorker.java
  ===================================================================
  //  Copyright 2004 The Apache Software Foundation
  //
  // Licensed under the Apache License, Version 2.0 (the "License");
  // you may not use this file except in compliance with the License.
  // You may obtain a copy of the License at
  //
  //     http://www.apache.org/licenses/LICENSE-2.0
  //
  // Unless required by applicable law or agreed to in writing, software
  // distributed under the License is distributed on an "AS IS" BASIS,
  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  // See the License for the specific language governing permissions and
  // limitations under the License.
  
  package org.apache.hivemind.impl;
  
  import org.apache.hivemind.Messages;
  import org.apache.hivemind.ShutdownCoordinator;
  import org.apache.hivemind.service.ClassFactory;
  import org.apache.hivemind.service.ThreadLocalStorage;
  
  /**
   * A service referenced by {@link org.apache.hivemind.impl.TestServiceModelThreading}.
   *
   * @author Howard Lewis Ship
   */
  public class StandardWorker implements Worker
  {
      // The issue may be in wiring/autowiring properties ... so add a bunch!
  
      private ClassFactory _classFactory;
      private ShutdownCoordinator _shutdownCoordinator;
      private Messages _messages;
      private String _serviceId;
      private ThreadLocalStorage _threadLocalStorage;
  
      public void initializeService()
      {
      }
  
      public void run(Runnable runnable)
      {
          _threadLocalStorage.put("thread-runnable", runnable);
  
          runnable.run();
      }
  
      public void setClassFactory(ClassFactory factory)
      {
          _classFactory = factory;
      }
  
      public void setMessages(Messages messages)
      {
          _messages = messages;
      }
  
      public void setServiceId(String string)
      {
          _serviceId = string;
      }
  
      public void setShutdownCoordinator(ShutdownCoordinator coordinator)
      {
          _shutdownCoordinator = coordinator;
      }
  
      public void setThreadLocalStorage(ThreadLocalStorage storage)
      {
          _threadLocalStorage = storage;
      }
  
  }
  
  
  
  1.1                  jakarta-hivemind/framework/src/test/org/apache/hivemind/impl/Worker.java
  
  Index: Worker.java
  ===================================================================
  //  Copyright 2004 The Apache Software Foundation
  //
  // Licensed under the Apache License, Version 2.0 (the "License");
  // you may not use this file except in compliance with the License.
  // You may obtain a copy of the License at
  //
  //     http://www.apache.org/licenses/LICENSE-2.0
  //
  // Unless required by applicable law or agreed to in writing, software
  // distributed under the License is distributed on an "AS IS" BASIS,
  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  // See the License for the specific language governing permissions and
  // limitations under the License.
  
  package org.apache.hivemind.impl;
  
  /**
   * A service referenced by {@link org.apache.hivemind.impl.TestServiceModelThreading}.
   *
   * @author Howard Lewis Ship
   */
  public interface Worker
  {
      public void run(Runnable runnable);
  }
  
  
  
  1.1                  jakarta-hivemind/framework/src/test/org/apache/hivemind/impl/ThreadedWorker.java
  
  Index: ThreadedWorker.java
  ===================================================================
  //  Copyright 2004 The Apache Software Foundation
  //
  // Licensed under the Apache License, Version 2.0 (the "License");
  // you may not use this file except in compliance with the License.
  // You may obtain a copy of the License at
  //
  //     http://www.apache.org/licenses/LICENSE-2.0
  //
  // Unless required by applicable law or agreed to in writing, software
  // distributed under the License is distributed on an "AS IS" BASIS,
  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  // See the License for the specific language governing permissions and
  // limitations under the License.
  
  package org.apache.hivemind.impl;
  
  import org.apache.hivemind.service.ThreadCleanupListener;
  
  /**
   * A service referenced by {@link org.apache.hivemind.impl.TestServiceModelThreading}.
   *
   * @author Howard Lewis Ship
   */
  public class ThreadedWorker extends StandardWorker implements ThreadCleanupListener
  {
  
      public void threadDidCleanup()
      {
          // Don't do anything, but we're checking code paths.
      }
  
  }
  
  
  
  1.1                  jakarta-hivemind/framework/src/test/org/apache/hivemind/impl/ServiceModelThreading.xml
  
  Index: ServiceModelThreading.xml
  ===================================================================
  <?xml version="1.0"?>
  <!-- 
     Copyright 2004 The Apache Software Foundation
  
     Licensed under the Apache License, Version 2.0 (the "License");
     you may not use this file except in compliance with the License.
     You may obtain a copy of the License at
  
         http://www.apache.org/licenses/LICENSE-2.0
  
     Unless required by applicable law or agreed to in writing, software
     distributed under the License is distributed on an "AS IS" BASIS,
     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     See the License for the specific language governing permissions and
     limitations under the License.
  -->
  <module id="hivemind.test.threading" version="1.0.0">
    
    <service-point id="PrimitiveWorker" interface="org.apache.hivemind.impl.Worker">
      <invoke-factory model="primitive" >
        <construct class="org.apache.hivemind.impl.StandardWorker"/>
      </invoke-factory>    <interceptor service-id="hivemind.LoggingInterceptor"/>
    </service-point>
    
   <service-point id="SingletonWorker" interface="org.apache.hivemind.impl.Worker">
      <invoke-factory>
        <construct class="org.apache.hivemind.impl.StandardWorker"/>
      </invoke-factory>
      <interceptor service-id="hivemind.LoggingInterceptor"/>
    </service-point>  
    
   <service-point id="ThreadedWorker" interface="org.apache.hivemind.impl.Worker">
      <invoke-factory model="pooled">
        <construct class="org.apache.hivemind.impl.StandardWorker"/>
      </invoke-factory>
      <interceptor service-id="hivemind.LoggingInterceptor"/>
    </service-point>   
    
   <service-point id="PooledWorker" interface="org.apache.hivemind.impl.Worker">
      <invoke-factory model="pooled" >
        <construct class="org.apache.hivemind.impl.StandardWorker"/>
      </invoke-factory>
      <interceptor service-id="hivemind.LoggingInterceptor"/>
    </service-point>    
    
  </module>
  
  
  1.1                  jakarta-hivemind/framework/src/test/org/apache/hivemind/impl/PooledWorker.java
  
  Index: PooledWorker.java
  ===================================================================
  //  Copyright 2004 The Apache Software Foundation
  //
  // Licensed under the Apache License, Version 2.0 (the "License");
  // you may not use this file except in compliance with the License.
  // You may obtain a copy of the License at
  //
  //     http://www.apache.org/licenses/LICENSE-2.0
  //
  // Unless required by applicable law or agreed to in writing, software
  // distributed under the License is distributed on an "AS IS" BASIS,
  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  // See the License for the specific language governing permissions and
  // limitations under the License.
  
  package org.apache.hivemind.impl;
  
  import org.apache.hivemind.PoolManageable;
  
  /**
   * A service referenced by {@link org.apache.hivemind.impl.TestServiceModelThreading}.
   *
   * @author Howard Lewis Ship
   */
  public class PooledWorker extends StandardWorker implements PoolManageable
  {
  
      public void activateService()
      {
  
      }
  
      public void passivateService()
      {
  
      }
  
  }
  
  
  
  1.6       +3 -1      jakarta-hivemind/framework/src/conf/log4j.properties
  
  Index: log4j.properties
  ===================================================================
  RCS file: /home/cvs/jakarta-hivemind/framework/src/conf/log4j.properties,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- log4j.properties	20 Jul 2004 17:26:25 -0000	1.5
  +++ log4j.properties	13 Aug 2004 13:19:15 -0000	1.6
  @@ -20,6 +20,8 @@
   
   # A1 uses PatternLayout.
   log4j.appender.A1.layout=org.apache.log4j.PatternLayout
  -log4j.appender.A1.layout.ConversionPattern=%c{1} [%p] %m%n
  +log4j.appender.A1.layout.ConversionPattern=%t -- %c{1} [%p] %m%n
   
   # log4j.category.org.apache.hivemind=warn
  +
  +# log4j.category.hivemind.test.threading=debug
  \ No newline at end of file
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: hivemind-cvs-unsubscribe@jakarta.apache.org
For additional commands, e-mail: hivemind-cvs-help@jakarta.apache.org


Mime
View raw message