Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[PDI-15635] - Changed implementations of collections, which are used …
…in multithreaded environment im order to get proper synchronization and better performance.
- Loading branch information
1 parent
d2df232
commit a4802f7
Showing
5 changed files
with
109 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
84 changes: 84 additions & 0 deletions
84
core/test-src/org/pentaho/di/core/logging/MetricsRegistryTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
/******************************************************************************* | ||
* | ||
* Pentaho Data Integration | ||
* | ||
* Copyright (C) 2002-2016 by Pentaho : http://www.pentaho.com | ||
* | ||
******************************************************************************* | ||
* | ||
* 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.pentaho.di.core.logging; | ||
|
||
import static org.junit.Assert.assertTrue; | ||
|
||
import org.junit.Before; | ||
import org.junit.Test; | ||
|
||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.Queue; | ||
import java.util.concurrent.Callable; | ||
import java.util.concurrent.CountDownLatch; | ||
import java.util.concurrent.ExecutorService; | ||
import java.util.concurrent.Executors; | ||
|
||
public class MetricsRegistryTest { | ||
private MetricsRegistry metricsRegistry; | ||
private List<String> logIds; | ||
private int threadCount = 100; | ||
private int logChannelIdCount = 20; | ||
private CountDownLatch countDownLatch = null; | ||
|
||
@Before | ||
public void setUp() { | ||
metricsRegistry = MetricsRegistry.getInstance(); | ||
logIds = new ArrayList<>( logChannelIdCount ); | ||
for ( int i = 1; i <= logChannelIdCount; i++ ) { | ||
logIds.add( "logChannelId_" + i ); | ||
} | ||
countDownLatch = new CountDownLatch( 1 ); | ||
} | ||
|
||
|
||
@Test( timeout = 2000 ) | ||
public void testConcurrencySnap() throws Exception { | ||
ExecutorService service = Executors.newFixedThreadPool( threadCount ); | ||
for ( int i = 0; i < threadCount; i++ ) { | ||
service.submit( new ConcurrentPutIfAbsent( logIds.get( i % 20 ) ) ); | ||
} | ||
countDownLatch.countDown(); | ||
service.shutdown(); | ||
while ( !service.isTerminated() ) { | ||
Thread.currentThread().sleep( 1 ); | ||
} | ||
int expectedQueueCount = logChannelIdCount > threadCount ? threadCount : logChannelIdCount; | ||
assertTrue( expectedQueueCount == metricsRegistry.getSnapshotLists().size() ); | ||
} | ||
|
||
private class ConcurrentPutIfAbsent implements Callable<Queue> { | ||
private String id; | ||
ConcurrentPutIfAbsent( String id ) { | ||
this.id = id; | ||
} | ||
@Override | ||
public Queue call() throws Exception { | ||
countDownLatch.await(); | ||
return metricsRegistry.getSnapshotList( id ); | ||
} | ||
|
||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters