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 org.apache.maven.index.context.IndexingContext;
23  import org.apache.maven.index.packer.IndexPacker;
24  import org.apache.maven.index.packer.IndexPackingRequest;
25  
26  import java.io.File;
27  import java.io.IOException;
28  import java.util.concurrent.atomic.AtomicInteger;
29  
30  /**
31   * The point in this test is: we use Merged context, and we modify some of the "members" in the merged context, while we
32   * try to publish those simultaneously.
33   *
34   * @author cstamas
35   */
36  public class ConcurrentUseWithMergedContextPublishingTest
37      extends ConcurrentUseWithMergedContextTest
38  {
39      protected IndexPacker packer;
40  
41      protected File repoPublish = new File( getBasedir(), "target/repo-publish" );
42  
43      protected final AtomicInteger counter = new AtomicInteger();
44  
45      @Override
46      protected void setUp()
47          throws Exception
48      {
49          super.setUp();
50  
51          packer = lookup( IndexPacker.class );
52      }
53  
54      @Override
55      protected void tearDown()
56          throws Exception
57      {
58          File props = new File( IndexingContext.INDEX_PACKER_PROPERTIES_FILE );
59          if ( props.exists() )
60          {
61              props.delete();
62          }
63          super.tearDown();
64      }
65  
66      @Override
67      protected int readIndex( final NexusIndexer nexusIndexer, final IndexingContext indexingContext )
68          throws IOException
69      {
70          // note: concurrent Index publishing into SAME directory is not supported and should be avoided.
71          // This test had multiple threads doing it, and since it was not checking actual results of publish (that was
72          // not the goal of the test, but simultaneous publishing of merged context that has member changes happening),
73          // it was probably publish rubbish anyway.
74          final File publish = new File( repoPublish, "publish-" + counter.getAndIncrement() );
75  
76          final IndexPackingRequest request = new IndexPackingRequest( context, publish );
77  
78          request.setCreateIncrementalChunks( false );
79  
80          packer.packIndex( request );
81  
82          return 1;
83      }
84  }