Skip to content

Commit 2f3e4a1

Browse files
authored
Update Galley to 1.8-SNAPSHOT and add NPMMetadataTimeoutNoSchedulerTest (#2063)
1 parent ee216ed commit 2f3e4a1

File tree

3 files changed

+164
-170
lines changed

3 files changed

+164
-170
lines changed
Lines changed: 159 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,159 @@
1+
/**
2+
* Copyright (C) 2011-2020 Red Hat, Inc. (https://github.com/Commonjava/indy)
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package org.commonjava.indy.pkg.npm.content;
17+
18+
import org.apache.commons.io.IOUtils;
19+
import org.commonjava.indy.client.core.IndyClientException;
20+
import org.commonjava.indy.ftest.core.AbstractContentManagementTest;
21+
import org.commonjava.indy.ftest.core.category.TimingDependent;
22+
import org.commonjava.indy.model.core.RemoteRepository;
23+
import org.commonjava.indy.model.core.io.IndyObjectMapper;
24+
import org.commonjava.indy.pkg.npm.model.DistTag;
25+
import org.commonjava.indy.pkg.npm.model.PackageMetadata;
26+
import org.junit.Test;
27+
import org.junit.experimental.categories.Category;
28+
29+
import java.io.IOException;
30+
import java.io.InputStream;
31+
32+
import static org.commonjava.indy.pkg.npm.model.NPMPackageTypeDescriptor.NPM_PKG_KEY;
33+
import static org.hamcrest.CoreMatchers.equalTo;
34+
import static org.hamcrest.CoreMatchers.notNullValue;
35+
import static org.junit.Assert.assertThat;
36+
37+
/**
38+
* This case tests if remote package.json will time out by using ONLY storage level timeout.
39+
* We need to disable scheduler in order to test it.
40+
* Given: <br />
41+
* <ul>
42+
* <li>remote repo A contains package.json for a given package</li>
43+
* <li>remote repo A metadata timeout is 1s</li>
44+
* </ul>
45+
* When: <br />
46+
* <ul>
47+
* <li>the first time package.json is retrieved via remote repo A by client</li>
48+
* <li>expect the remote server with new version in package.json</li>
49+
* <li>wait for 3s for the cached file to timeout</li>
50+
* <li>the second time package.json is retrieved via remote repo A</li>
51+
* </ul>
52+
* Then: <br />
53+
* <ul>
54+
* <li>the version 1 of package.json expires in remote repository A, the version 2 is retrieved successfully</li>
55+
* </ul>
56+
*/
57+
public class NPMMetadataTimeoutNoSchedulerTest
58+
extends AbstractContentManagementTest
59+
{
60+
61+
private static final String REPO = "A";
62+
63+
private static final String PATH_JQUERY = "jquery";
64+
65+
private static final String PATH_BABEL_PARSER = "@babel/parser";
66+
67+
// !!!IMPORTANT: disable scheduler in order to test storage level timeout
68+
@Override
69+
protected boolean isSchedulerEnabled()
70+
{
71+
return false;
72+
}
73+
74+
@Test
75+
@Category( TimingDependent.class )
76+
public void test()
77+
throws Exception
78+
{
79+
IndyObjectMapper mapper = new IndyObjectMapper( true );
80+
81+
final PackageMetadata src = new PackageMetadata();
82+
final DistTag dts = new DistTag();
83+
dts.setBeta( "1" );
84+
src.setDistTags( dts );
85+
86+
server.expect( "GET", server.formatUrl( REPO, PATH_JQUERY ), ( req, resp ) -> {
87+
resp.setStatus( 200 );
88+
mapper.writeValue( resp.getWriter(), src );
89+
resp.getWriter().flush();
90+
} );
91+
92+
server.expect( "GET", server.formatUrl( REPO, PATH_BABEL_PARSER ), ( req, resp ) -> {
93+
resp.setStatus( 200 );
94+
mapper.writeValue( resp.getWriter(), src );
95+
resp.getWriter().flush();
96+
} );
97+
98+
final RemoteRepository repo = new RemoteRepository( NPM_PKG_KEY, REPO, server.formatUrl( REPO ) );
99+
repo.setMetadataTimeoutSeconds( 1 );
100+
101+
client.stores().create( repo, "adding npm remote repo", RemoteRepository.class );
102+
103+
// First retrieval
104+
verifyMetadataBetaTag( "1", PATH_JQUERY, repo );
105+
assertThat( "Metadata not retrieved!", client.content().exists( repo.getKey(), PATH_JQUERY, true ),
106+
equalTo( true ) );
107+
assertThat( "Metadata not retrieved!",
108+
client.content().exists( repo.getKey(), PATH_JQUERY + "/package.json", true ), equalTo( true ) );
109+
110+
verifyMetadataBetaTag( "1", PATH_BABEL_PARSER, repo );
111+
assertThat( "Metadata not retrieved!", client.content().exists( repo.getKey(), PATH_BABEL_PARSER, true ),
112+
equalTo( true ) );
113+
assertThat( "Metadata not retrieved!",
114+
client.content().exists( repo.getKey(), PATH_BABEL_PARSER + "/package.json", true ),
115+
equalTo( true ) );
116+
117+
// wait for repo metadata timeout
118+
Thread.sleep( 3000 );
119+
120+
assertThat( "Metadata not cleaned up!", client.content().exists( repo.getKey(), PATH_JQUERY, true ),
121+
equalTo( false ) );
122+
assertThat( "Metadata not cleaned up!",
123+
client.content().exists( repo.getKey(), PATH_JQUERY + "/package.json", true ), equalTo( false ) );
124+
125+
assertThat( "Metadata not cleaned up!", client.content().exists( repo.getKey(), PATH_BABEL_PARSER, true ),
126+
equalTo( false ) );
127+
assertThat( "Metadata not cleaned up!",
128+
client.content().exists( repo.getKey(), PATH_BABEL_PARSER + "/package.json", true ),
129+
equalTo( false ) );
130+
131+
132+
logger.info( "\n\n\n\nRE-REQUEST STARTS HERE\n\n\n\n" );
133+
134+
// Second retrieval
135+
dts.setBeta( "2" );
136+
verifyMetadataBetaTag( "2", PATH_JQUERY, repo );
137+
verifyMetadataBetaTag( "2", PATH_BABEL_PARSER, repo );
138+
}
139+
140+
private void verifyMetadataBetaTag( final String betaTag, final String path, RemoteRepository repo )
141+
throws IndyClientException, IOException
142+
{
143+
try (InputStream remote = client.content().get( repo.getKey(), path ))
144+
{
145+
assertThat( remote, notNullValue() );
146+
String json = IOUtils.toString( remote );
147+
PackageMetadata merged =
148+
new IndyObjectMapper( true ).readValue( json, PackageMetadata.class );
149+
150+
assertThat( merged.getDistTags().getBeta(), equalTo( betaTag ) );
151+
}
152+
}
153+
154+
@Override
155+
protected boolean createStandardTestStructures()
156+
{
157+
return false;
158+
}
159+
}

core/src/main/java/org/commonjava/indy/core/conf/IndySchedulerConfig.java

Lines changed: 4 additions & 169 deletions
Original file line numberDiff line numberDiff line change
@@ -16,202 +16,37 @@
1616
package org.commonjava.indy.core.conf;
1717

1818
import org.commonjava.indy.conf.IndyConfigInfo;
19-
import org.commonjava.propulsor.config.ConfigurationException;
19+
import org.commonjava.propulsor.config.annotation.ConfigName;
2020
import org.commonjava.propulsor.config.annotation.SectionName;
21-
import org.commonjava.propulsor.config.section.MapSectionListener;
2221

2322
import javax.enterprise.context.ApplicationScoped;
2423
import java.io.InputStream;
25-
import java.util.HashMap;
26-
import java.util.Map;
27-
import java.util.Properties;
2824

2925
@ApplicationScoped
3026
@SectionName( IndySchedulerConfig.SECTION_NAME )
3127
public class IndySchedulerConfig
32-
extends MapSectionListener
3328
implements IndyConfigInfo
3429
{
35-
36-
//TODO: All quartz related function for content expiration has been
37-
// replaced by ISPN cache timeout way. Will be removed in future
38-
3930
public static final String SECTION_NAME = "scheduler";
4031

4132
private static final String ENABLED_PROP = "enabled";
4233

43-
private static final String CLUSTER_LOCK_EXPIRATION = "schedule.cluster.lock.expiration.sec";
44-
45-
// @Deprecated
46-
// private static final String QUARTZ_DATASOURCE_PREFIX = "org.quartz.dataSource.ds.";
47-
//
48-
// @Deprecated
49-
// private static final String DS_DRIVER = "driver";
50-
//
51-
// @Deprecated
52-
// private static final String DS_URL = "URL";
53-
//
54-
// @Deprecated
55-
// private static final String DDL_PROP = "ddl";
56-
//
57-
// @Deprecated
58-
// private static final String DEFAULT_DB_URL =
59-
// String.format( "jdbc:derby:%s/var/lib/indy/data/scheduler",
60-
// System.getProperty( "indy.home", System.getProperty( "java.io.tmpdir" ) ) );
61-
//
62-
// @Deprecated
63-
// private static final String DEFAULT_DB_DRIVER = "org.apache.derby.jdbc.EmbeddedDriver";
64-
6534
private static final boolean DEFAULT_ENABLED = true;
6635

67-
private static final int DEFAULT_CLUSTER_LOCK_EXPIRATION = 3600;
68-
6936
private Boolean enabled;
7037

71-
private Integer clusterLockExpiration;
72-
73-
// @Deprecated
74-
// private transient boolean dbDetailsParsed;
75-
//
76-
// @Deprecated
77-
// private transient String ddlFile;
78-
//
79-
// @Deprecated
80-
// private transient String dbUrl;
81-
//
82-
// @Deprecated
83-
// private transient String dbDriver;
84-
8538
public IndySchedulerConfig()
8639
{
8740
}
8841

89-
public IndySchedulerConfig( final Properties props )
90-
throws ConfigurationException
91-
{
92-
this.sectionStarted( SECTION_NAME );
93-
for ( final String key : props.stringPropertyNames() )
94-
{
95-
this.parameter( key, props.getProperty( key ) );
96-
}
97-
}
98-
99-
// @Deprecated
100-
// private synchronized void parseDatabaseDetails()
101-
// {
102-
// if ( !dbDetailsParsed )
103-
// {
104-
// dbDetailsParsed = true;
105-
//
106-
// final Map<String, String> configMap = getConfiguration();
107-
// if ( configMap == null )
108-
// {
109-
// return;
110-
// }
111-
//
112-
// for ( final Map.Entry<String, String> entry : configMap.entrySet() )
113-
// {
114-
// final String key = entry.getKey();
115-
// if ( ENABLED_PROP.equalsIgnoreCase( key ) )
116-
// {
117-
// enabled = Boolean.parseBoolean( entry.getValue().toLowerCase() );
118-
// }
119-
// else if ( DDL_PROP.equalsIgnoreCase( key ) )
120-
// {
121-
// ddlFile = entry.getValue();
122-
// }
123-
// else if ( key.startsWith( QUARTZ_DATASOURCE_PREFIX ) )
124-
// {
125-
// if ( key.endsWith( DS_DRIVER ) )
126-
// {
127-
// this.dbDriver = entry.getValue();
128-
// }
129-
// else if ( key.endsWith( DS_URL ) )
130-
// {
131-
// this.dbUrl = entry.getValue();
132-
// }
133-
// }
134-
// }
135-
// }
136-
// }
137-
13842
public boolean isEnabled()
13943
{
14044
return enabled == null ? DEFAULT_ENABLED : enabled;
14145
}
14246

143-
public int getClusterLockExpiration()
144-
{
145-
return clusterLockExpiration == null ? DEFAULT_CLUSTER_LOCK_EXPIRATION : clusterLockExpiration;
146-
}
147-
148-
// @Deprecated
149-
// public String getDdlFile()
150-
// {
151-
// parseDatabaseDetails();
152-
// return ddlFile;
153-
// }
154-
//
155-
// @Deprecated
156-
// public String getDbUrl()
157-
// {
158-
// parseDatabaseDetails();
159-
// return dbUrl == null ? DEFAULT_DB_URL : dbUrl;
160-
// }
161-
//
162-
// @Deprecated
163-
// public String getDbDriver()
164-
// {
165-
// parseDatabaseDetails();
166-
// return dbDriver == null ? DEFAULT_DB_DRIVER : dbDriver;
167-
// }
168-
169-
// public CharSequence validate()
170-
// {
171-
// parseDatabaseDetails();
172-
// final StringBuilder sb = new StringBuilder();
173-
// if ( dbDriver == null )
174-
// {
175-
// if ( sb.length() > 0 )
176-
// {
177-
// sb.append( "\n" );
178-
// }
179-
// sb.append( "Missing database driver (" )
180-
// .append( QUARTZ_DATASOURCE_PREFIX )
181-
// .append( DS_DRIVER )
182-
// .append( ")" );
183-
// }
184-
//
185-
// if ( dbUrl == null )
186-
// {
187-
// if ( sb.length() > 0 )
188-
// {
189-
// sb.append( "\n" );
190-
// }
191-
// sb.append( "Missing database URL (" )
192-
// .append( QUARTZ_DATASOURCE_PREFIX )
193-
// .append( DS_URL )
194-
// .append( ")" );
195-
// }
196-
//
197-
// if ( sb.length() > 0 )
198-
// {
199-
// return sb;
200-
// }
201-
//
202-
// return null;
203-
// }
204-
205-
@Override
206-
public Map<String, String> getConfiguration()
207-
{
208-
Map<String, String> configuration = super.getConfiguration();
209-
if ( configuration == null )
210-
{
211-
configuration = new HashMap<>();
212-
}
213-
214-
return configuration;
47+
@ConfigName( ENABLED_PROP )
48+
public void setEnabled(Boolean enabled) {
49+
this.enabled = enabled;
21550
}
21651

21752
@Override

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@
9090

9191
<!-- commonjava/redhat projects -->
9292
<atlasVersion>1.1.1</atlasVersion>
93-
<galleyVersion>1.7</galleyVersion>
93+
<galleyVersion>1.8-SNAPSHOT</galleyVersion>
9494
<bomVersion>25</bomVersion>
9595
<webdavVersion>3.2.1</webdavVersion>
9696
<partylineVersion>1.16</partylineVersion>

0 commit comments

Comments
 (0)