View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  package org.apache.maven.index;
20  
21  import java.util.Arrays;
22  
23  import org.apache.lucene.store.ByteBuffersDirectory;
24  import org.apache.lucene.store.Directory;
25  import org.apache.maven.index.context.IndexingContext;
26  
27  import static org.junit.Assert.assertNotNull;
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 extends ConcurrentUseTest {
36      protected Directory indexDir1 = new ByteBuffersDirectory();
37  
38      protected IndexingContext context1;
39  
40      protected Directory indexDir2 = new ByteBuffersDirectory();
41  
42      protected IndexingContext context2;
43  
44      @Override
45      protected void prepareNexusIndexer(NexusIndexer nexusIndexer) throws Exception {
46          context1 = nexusIndexer.addIndexingContext(
47                  "test-default-member1", "test1", repo, indexDir1, null, null, DEFAULT_CREATORS);
48  
49          nexusIndexer.scan(context1);
50  
51          context2 = nexusIndexer.addIndexingContext(
52                  "test-default-member2", "test2", repo, indexDir2, null, null, DEFAULT_CREATORS);
53  
54          nexusIndexer.scan(context2);
55  
56          context = nexusIndexer.addMergedIndexingContext(
57                  "test-default", "test", repo, indexDir, true, Arrays.asList(context1, context2));
58  
59          // Group contexts are known, they inherit member timestamp and they are scanned already
60          // assertNull( context.getTimestamp() ); // unknown upon creation
61  
62          // nexusIndexer.scan( context );
63  
64          assertNotNull(context.getTimestamp());
65      }
66  
67      @Override
68      protected IndexUserThread createThread(final ArtifactInfo ai) {
69          // we search the merged one and modify one member context concurrently
70          return new IndexUserThread(this, nexusIndexer, context, context1, ai);
71      }
72  }