Search in sources :

Example 1 with NonAccessibleFileObject

use of org.pentaho.di.core.fileinput.NonAccessibleFileObject in project pentaho-kettle by pentaho.

the class BaseStepTest method resultFilesMapIsSafeForConcurrentModification.

@Test
public void resultFilesMapIsSafeForConcurrentModification() throws Exception {
    final BaseStep step = new BaseStep(mockHelper.stepMeta, mockHelper.stepDataInterface, 0, mockHelper.transMeta, mockHelper.trans);
    final AtomicBoolean complete = new AtomicBoolean(false);
    final int FILES_AMOUNT = 10 * 1000;
    Thread filesProducer = new Thread(new Runnable() {

        @Override
        public void run() {
            try {
                for (int i = 0; i < FILES_AMOUNT; i++) {
                    step.addResultFile(new ResultFile(0, new NonAccessibleFileObject(Integer.toString(i)), null, null));
                    try {
                        Thread.sleep(1);
                    } catch (Exception e) {
                        fail(e.getMessage());
                    }
                }
            } finally {
                complete.set(true);
            }
        }
    });
    filesProducer.start();
    try {
        while (!complete.get()) {
            for (Map.Entry<String, ResultFile> entry : step.getResultFiles().entrySet()) {
                entry.getKey();
            }
        }
    } finally {
        filesProducer.join();
    }
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) ValueMetaString(org.pentaho.di.core.row.value.ValueMetaString) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) ResultFile(org.pentaho.di.core.ResultFile) Map(java.util.Map) NonAccessibleFileObject(org.pentaho.di.core.fileinput.NonAccessibleFileObject) KettleValueException(org.pentaho.di.core.exception.KettleValueException) KettleStepException(org.pentaho.di.core.exception.KettleStepException) KettleException(org.pentaho.di.core.exception.KettleException) IOException(java.io.IOException) Test(org.junit.Test)

Aggregations

IOException (java.io.IOException)1 Map (java.util.Map)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)1 Test (org.junit.Test)1 ResultFile (org.pentaho.di.core.ResultFile)1 KettleException (org.pentaho.di.core.exception.KettleException)1 KettleStepException (org.pentaho.di.core.exception.KettleStepException)1 KettleValueException (org.pentaho.di.core.exception.KettleValueException)1 NonAccessibleFileObject (org.pentaho.di.core.fileinput.NonAccessibleFileObject)1 ValueMetaString (org.pentaho.di.core.row.value.ValueMetaString)1