Skip to content

Commit

Permalink
cleanup deprecated and outdated things (#979)
Browse files Browse the repository at this point in the history
  • Loading branch information
bennetelli committed Mar 23, 2023
1 parent d8ca893 commit daceb5e
Show file tree
Hide file tree
Showing 14 changed files with 17 additions and 332 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@
/**
* Activation strategy that enables features for a given percentage of users. This strategy is typically used to implement
* gradual rollouts. The implementation is based on a hashcode created from the name of the acting user which is calculated by
* {@link #calculateHashCode(FeatureUser)}.
*
* @author Christian Kaltepoth
* {@link #calculateHashCode(FeatureUser, Feature)}.
*/
public class GradualActivationStrategy implements ActivationStrategy {

Expand All @@ -37,36 +35,21 @@ public String getName() {

@Override
public boolean isActive(FeatureState state, FeatureUser user) {

if (user != null && Strings.isNotBlank(user.getName())) {

String percentageAsString = state.getParameter(PARAM_PERCENTAGE);
try {

int percentage = Integer.parseInt(percentageAsString);

if (percentage > 0) {
int hashCode = Math.abs(calculateHashCode(user, state.getFeature()));
return (hashCode % 100) < percentage;
}

} catch (NumberFormatException e) {
log.error("Invalid gradual rollout percentage for feature " + state.getFeature().name() + ": "
+ percentageAsString);
}

}

return false;

}

/**
* @deprecated Use {@link #calculateHashCode(FeatureUser, Feature)} instead
*/
@Deprecated
protected int calculateHashCode(FeatureUser user) {
return calculateHashCode(user, null);
}

protected int calculateHashCode(FeatureUser user, Feature feature) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

/**
* Builder of {@link DefaultFeatureManager}.
*
*
* @author Christian Kaltepoth
*/
public class FeatureManagerBuilder {
Expand All @@ -41,14 +41,6 @@ public FeatureManagerBuilder stateRepository(StateRepository stateRepository) {
return this;
}

/**
* Use {@link #featureEnum(Class)} instead.
*/
@Deprecated
public FeatureManagerBuilder featureClass(Class<? extends Feature> featureClass) {
return this.featureEnum(featureClass);
}

/**
* Use the supplied feature enum class for the feature manager. Same as calling {@link #featureProvider(FeatureProvider)}
* with {@link EnumBasedFeatureProvider}. Please note calling this method also set the name of the feature manager to the
Expand All @@ -63,7 +55,8 @@ public FeatureManagerBuilder featureEnum(Class<? extends Feature> featureEnum) {
* with {@link EnumBasedFeatureProvider}. Please note calling this method also set the name of the feature manager to the
* simple name of the first feature enum's type.
*/
public FeatureManagerBuilder featureEnums(Class<? extends Feature>... featureEnum) {
@SafeVarargs
public final FeatureManagerBuilder featureEnums(Class<? extends Feature>... featureEnum) {
this.featureProvider = new EnumBasedFeatureProvider(featureEnum);
this.name = "FeatureManager[" + featureEnum[0].getSimpleName() + "]";
return this;
Expand Down
72 changes: 2 additions & 70 deletions core/src/main/java/org/togglz/core/repository/FeatureState.java
Original file line number Diff line number Diff line change
@@ -1,20 +1,15 @@
package org.togglz.core.repository;

import org.togglz.core.Feature;

import java.io.Serializable;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Objects;
import java.util.Set;

import org.togglz.core.Feature;
import org.togglz.core.activation.UsernameActivationStrategy;
import org.togglz.core.util.Strings;

/**
* This class represents the state of a feature that is persisted by {@link StateRepository} implementations.
*
Expand Down Expand Up @@ -50,25 +45,6 @@ public FeatureState(Feature feature, boolean enabled) {
this.enabled = enabled;
}

/**
* This constructor creates a new feature state for the given feature. Please not that using this constructor will
* automatically set strategyId to match the {@link UsernameActivationStrategy}.
*
* @param feature The feature that is represented by this state.
* @param enabled boolean indicating whether this feature should be enabled or not.
* @param users A list of users
*
* @deprecated This constructor will be removed soon. You should use {@link #FeatureState(Feature, boolean)} and
* {@link #setParameter(String, String)} instead.
*/
@Deprecated
public FeatureState(Feature feature, boolean enabled, List<String> users) {
this.feature = feature;
this.enabled = enabled;
this.strategyId = UsernameActivationStrategy.ID;
this.addUsers(users);
}

/**
* Creates a copy of this state object
*/
Expand Down Expand Up @@ -120,50 +96,6 @@ public FeatureState disable() {
return setEnabled(false);
}

/**
* The list of users associated with the feature state.
*
* @return The user list, never <code>null</code>
*
* @deprecated This method will be removed soon. Use {@link #getParameter(String)} instead to read the corresponding
* strategy parameter.
*/
@Deprecated
public List<String> getUsers() {
String value = getParameter(UsernameActivationStrategy.PARAM_USERS);
if (Strings.isNotBlank(value)) {
return Strings.splitAndTrim(value, ",");
}
return Collections.emptyList();
}

/**
* Adds a single user to the list of users
*
* @deprecated This method will be removed soon. Use {@link #setParameter(String, String)} instead to modify the
* corresponding strategy parameter.
*/
@Deprecated
public FeatureState addUser(String user) {
return this.addUsers(Collections.singletonList(user));
}

/**
* Adds a single user to the list of users
*
* @deprecated This method will be removed soon. Use {@link #setParameter(String, String)} instead to modify the
* corresponding strategy parameter.
*/
@Deprecated
public FeatureState addUsers(Collection<String> users) {
Set<String> set = new LinkedHashSet<>();
set.addAll(this.getUsers());
set.addAll(users);
String setAsString = Strings.trimToNull(Strings.join(set, ","));
setParameter(UsernameActivationStrategy.PARAM_USERS, setAsString);
return this;
}

/**
* Returns the ID of the selected activation strategy.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,50 +94,6 @@ public JDBCStateRepository(DataSource dataSource, String tableName) {
this(new Builder(dataSource).tableName(tableName));
}

/**
* Constructor of {@link JDBCStateRepository}.
*
* @param dataSource The JDBC {@link DataSource} to obtain connections from
* @param tableName The name of the database table to use
* @param createTable If set to <code>true</code>, the table will be automatically created if it is missing
* @deprecated use {@link JDBCStateRepository#newBuilder(DataSource)} to create a builder that can be used to configure all
* aspects of the repository in a fluent way
*/
@Deprecated
public JDBCStateRepository(DataSource dataSource, String tableName, boolean createTable) {
this(new Builder(dataSource).tableName(tableName).createTable(createTable));
}

/**
* Constructor of {@link JDBCStateRepository}.
*
* @param dataSource The JDBC {@link DataSource} to obtain connections from
* @param tableName The name of the database table to use
* @param createTable If set to <code>true</code>, the table will be automatically created if it is missing
* @param serializer The {@link MapSerializer} for storing parameters
* @deprecated use {@link JDBCStateRepository#newBuilder(DataSource)} to create a builder that can be used to configure all
* aspects of the repository in a fluent way
*/
@Deprecated
public JDBCStateRepository(DataSource dataSource, String tableName, boolean createTable, MapSerializer serializer) {
this(new Builder(dataSource).tableName(tableName).createTable(createTable).serializer(serializer));
}

/**
* Constructor of {@link JDBCStateRepository}.
*
* @param dataSource The JDBC {@link DataSource} to obtain connections from
* @param tableName The name of the database table to use
* @param createTable If set to <code>true</code>, the table will be automatically created if it is missing
* @param serializer The {@link MapSerializer} for storing parameters
* @deprecated use {@link JDBCStateRepository#newBuilder(DataSource)} to create a builder that can be used to configure all
* aspects of the repository in a fluent way
*/
public JDBCStateRepository(DataSource dataSource, String tableName, boolean createTable, MapSerializer serializer,
boolean noCommit) {
this(new Builder(dataSource).tableName(tableName).createTable(createTable).serializer(serializer).noCommit(noCommit));
}

/**
* Private constructor initializing the class from a builder
*/
Expand Down Expand Up @@ -424,7 +380,5 @@ public Builder usePostgresTextColumns(boolean usePostgresTextColumns) {
public JDBCStateRepository build() {
return new JDBCStateRepository(this);
}

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@

import org.junit.jupiter.api.Test;
import org.togglz.core.Feature;
import org.togglz.core.activation.UsernameActivationStrategy;

import java.util.Arrays;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
Expand Down Expand Up @@ -35,24 +32,6 @@ void testSimpleFeatureState() {
assertEquals(0, state.getParameterNames().size());
}

@Test
void testOldUsersApiHandling() {

// initial state
FeatureState state = new FeatureState(Features.FEATURE1, true, Arrays.asList("ck", "admin"));
assertTrue(state.isEnabled());
assertTrue(state.getParameterNames().contains(UsernameActivationStrategy.PARAM_USERS));
assertEquals("ck,admin", state.getParameter(UsernameActivationStrategy.PARAM_USERS));
assertTrue(state.getUsers().containsAll(Arrays.asList("ck", "admin")));

// add some other user
state.addUser("tester");
assertEquals("ck,admin,tester", state.getParameter(UsernameActivationStrategy.PARAM_USERS));
assertEquals(state.getUsers().get(0), "ck");
assertEquals(state.getUsers().get(1), "admin");
assertEquals(state.getUsers().get(2), "tester");
}

@Test
void testEquals() {

Expand Down
14 changes: 2 additions & 12 deletions junit/src/main/java/org/togglz/junit/WithFeature.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
package org.togglz.junit;

import static java.lang.annotation.ElementType.METHOD;
import static java.lang.annotation.RetentionPolicy.RUNTIME;

import java.lang.annotation.Retention;
import java.lang.annotation.Target;

import org.togglz.core.Feature;
import static java.lang.annotation.ElementType.METHOD;
import static java.lang.annotation.RetentionPolicy.RUNTIME;

/**
* Used together with the {@link TogglzRule} on test methods.
Expand All @@ -15,13 +13,6 @@
@Retention(RUNTIME)
public @interface WithFeature
{

/**
* @deprecated Removed without replacement
*/
@Deprecated
Class<? extends Feature> type() default Feature.class;

/**
* The features to enable
*/
Expand All @@ -31,5 +22,4 @@
* disable the features instead of enabling them
*/
boolean disable() default false;

}
13 changes: 0 additions & 13 deletions junit/src/main/java/org/togglz/junit/vary/VariationSet.java

This file was deleted.

55 changes: 0 additions & 55 deletions junit/src/main/java/org/togglz/junit/vary/VariationSetBuilder.java

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

import org.junit.Test;
import org.junit.runner.RunWith;
import org.togglz.testing.vary.VariationSet;
import org.togglz.testing.vary.VariationSetBuilder;

@RunWith(FeatureVariations.class)
public class FeatureVariationsTest {
Expand Down

0 comments on commit daceb5e

Please sign in to comment.