View Javadoc

1   package org.apache.maven.index;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *   http://www.apache.org/licenses/LICENSE-2.0    
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
20   */
21  
22  import java.util.Arrays;
23  
24  import org.apache.lucene.store.Directory;
25  import org.apache.lucene.store.RAMDirectory;
26  import org.apache.maven.index.context.DefaultIndexingContext;
27  import org.apache.maven.index.context.IndexingContext;
28  
29  /**
30   * The point in this test is: we use Merged context, and we modify some of the "members" in the merged context, while we
31   * try to search over merged one simultaneously.
32   * 
33   * @author cstamas
34   */
35  public class ConcurrentUseWithMergedContextTest
36      extends ConcurrentUseTest
37  {
38      protected Directory indexDir1 = new RAMDirectory();
39  
40      protected IndexingContext context1;
41  
42      protected Directory indexDir2 = new RAMDirectory();
43  
44      protected IndexingContext context2;
45  
46      @Override
47      protected void prepareNexusIndexer( NexusIndexer nexusIndexer )
48          throws Exception
49      {
50          // This IS concurrent test, so here, unlike all other UTs, we DO want to have async commits
51          DefaultIndexingContext.BLOCKING_COMMIT = false;
52  
53          context1 =
54              nexusIndexer.addIndexingContext( "test-default-member1", "test1", repo, indexDir1, null, null,
55                  DEFAULT_CREATORS );
56  
57          nexusIndexer.scan( context1 );
58  
59          context2 =
60              nexusIndexer.addIndexingContext( "test-default-member2", "test2", repo, indexDir2, null, null,
61                  DEFAULT_CREATORS );
62  
63          nexusIndexer.scan( context2 );
64  
65          context =
66              nexusIndexer.addMergedIndexingContext( "test-default", "test", repo, indexDir, true,
67                  Arrays.asList( context1, context2 ) );
68  
69          // Group contexts are known, they inherit member timestamp and they are scanned already
70          // assertNull( context.getTimestamp() ); // unknown upon creation
71  
72          // nexusIndexer.scan( context );
73  
74          assertNotNull( context.getTimestamp() );
75      }
76  
77      @Override
78      protected IndexUserThread createThread( final ArtifactInfo ai )
79      {
80          // we search the merged one and modify one member context concurrently
81          return new IndexUserThread( this, nexusIndexer, context, context1, ai );
82      }
83  }