Giter VIP home page Giter VIP logo

Comments (3)

writencode avatar writencode commented on June 3, 2024

I'm happy to contribute a fix for it - please let me know how I can do that.

from ff4j.

writencode avatar writencode commented on June 3, 2024

Simple test to support this jira

package org.ff4j.test.strategy;

/*-
 * #%L
 * ff4j-core
 * %%
 * Copyright (C) 2013 - 2023 FF4J
 * %%
 * 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.
 * #L%
 */

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.ff4j.strategy.time.ReleaseDateFlipStrategy;
import org.junit.Test;

import java.text.ParseException;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.CountDownLatch;

import static org.ff4j.strategy.time.ReleaseDateFlipStrategy.PARAMNAME_RELEASEDATE;


import static org.junit.Assert.assertEquals;
import static org.junit.runners.model.MultipleFailureException.assertEmpty;


/**
 * Testing class for {@link ReleaseDateFlipStrategy} class.
 *
 * @author Henry Naftulin
 */
public class ReleaseDateFlipStrategyMultiThreadTest {
    protected final Log logger = LogFactory.getLog(getClass());

    public static String[] validDates = {
            "2023-01-01-10:22",
            "2023-01-01-10:23",
            "2023-01-01-10:24",
            "2023-01-01-10:25",
            "2023-01-01-10:26",
            "2023-01-01-10:27"
    };
    int numThreads = 40;
    private static CountDownLatch latch;

    private List<FeatureDateRunnable> runnables = new ArrayList<>();
    private static List<String> errors = new ArrayList<>();


    @Test
    public void testMultipleThreads() throws ParseException, InterruptedException {
        for(int i=0; i<numThreads; i++) {
            runnables.add(new FeatureDateRunnable(validDates[i%validDates.length]));
        }
        latch = new CountDownLatch(numThreads);
        for(Runnable r : runnables) {
            new Thread(r).start();
        }
        latch.await();
        logger.info("Ran "+ numThreads + " trials, got errors in " + errors.size() + " trials");
        assertEquals(new ArrayList<>(), errors);
    }


    static class FeatureDateRunnable implements Runnable {
        protected final Log logger = LogFactory.getLog(getClass());
        private String strDate;

        public FeatureDateRunnable(String strDate) {
            this.strDate = strDate;
        }
        public void run() {
            try {
                ReleaseDateFlipStrategy strategy = new ReleaseDateFlipStrategy(strDate);
            } catch(Throwable t) {
                String message = "Exception thrown when creating ReleaseDateFlipStrategy with date: " + strDate;
                errors.add(message);
                logger.error(message, t);
            } finally {
                latch.countDown();
            }
        }
    }


}

from ff4j.

writencode avatar writencode commented on June 3, 2024

Pull request created: #707

from ff4j.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.