Skip to content

Commit

Permalink
Fixed comments
Browse files Browse the repository at this point in the history
  • Loading branch information
sajid riaz committed Sep 9, 2024
1 parent d276530 commit 849adfb
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 65 deletions.
4 changes: 2 additions & 2 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## Version 1.0.0 (Not yet Release)

* Retry Policy for Jmx Connection -Issue #700
* Update Architecture and Tests Documentations to Add the Agent Features and The cassandra-test-image - Issue #707
* Enhance Test Infrastructure by Adding Cassandra-Test-Image Module With Multi-Datacenter Cluster and Abstract Integration Test Class - Issue #706
* Investigate Introduction of testContainers - Issue #682
Expand All @@ -10,5 +11,4 @@
* Create JMXAgentConfig to add Hosts in JMX Session Through ecc.yml - Issue #675
* Expose AgentNativeConnectionProvider on Connection and Application Module - Issue #673
* Create DatacenterAwareConfig to add Hosts in CQL Session Through ecc.yml - Issue #671
* Create Initial project Structure for Agent - Issue #695
* Retry Policy for Jmx Connection -Issue #700
* Create Initial project Structure for Agent - Issue #695
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,19 @@ public class ConnectionConfig
private DistributedNativeConnection myCqlConnection = new DistributedNativeConnection();
private DistributedJmxConnection myJmxConnection = new DistributedJmxConnection();

@JsonProperty ("cql")
@JsonProperty("cql")
public final DistributedNativeConnection getCqlConnection()
{
return myCqlConnection;
}

@JsonProperty ("jmx")
@JsonProperty("jmx")
public final DistributedJmxConnection getJmxConnection()
{
return myJmxConnection;
}

@JsonProperty ("cql")
@JsonProperty("cql")
public final void setCqlConnection(final DistributedNativeConnection cqlConnection)
{
if (cqlConnection != null)
Expand All @@ -42,7 +42,7 @@ public final void setCqlConnection(final DistributedNativeConnection cqlConnecti
}
}

@JsonProperty ("jmx")
@JsonProperty("jmx")
public final void setJmxConnection(final DistributedJmxConnection jmxConnection)
{
if (jmxConnection != null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,13 @@ public DistributedJmxConnection()
}
}

@JsonProperty ("retryPolicy")
@JsonProperty("retryPolicy")
public final RetryPolicyConfig getRetryPolicyConfig()
{
return myRetryPolicyConfig;
}

@JsonProperty ("retryPolicy")
@JsonProperty("retryPolicy")
public final void setRetryPolicyConfig(final RetryPolicyConfig retryPolicyConfig)
{
myRetryPolicyConfig = retryPolicyConfig;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,11 @@ public RetryPolicyConfig()
private static final long DEFAULT_MAX_DELAY_IN_MS = 30000;
private static final long DEFAULT_INITIAL_DELAY_IN_MS = 86400000;
private static final long DEFAULT_FIXED_DELAY_IN_MS = 86400000;
private static final String DEFAULT_TIME_UNIT_IN_SECONDS = "seconds";
private static final TimeUnit DEFAULT_TIME_UNIT_IN_SECONDS = TimeUnit.SECONDS;
private RetryPolicyConfig.RetryDelay myRetryDelay = new RetryPolicyConfig.RetryDelay();
private RetryPolicyConfig.RetrySchedule myRetrySchedule = new RetryPolicyConfig.RetrySchedule();
@JsonProperty ("maxAttempts")

@JsonProperty("maxAttempts")
private Integer myMaxAttempts = DEFAULT_MAX_ATTEMPTS;

@JsonProperty ("maxAttempts")
Expand All @@ -41,7 +42,7 @@ public Integer getMaxAttempts()
return myMaxAttempts;
}

@JsonProperty ("maxAttempts")
@JsonProperty("maxAttempts")
public void setMaxAttempts(final Integer maxAttempts)
{
if (maxAttempts != null)
Expand All @@ -50,41 +51,33 @@ public void setMaxAttempts(final Integer maxAttempts)
}
}

@JsonProperty ("delay")
@JsonProperty("delay")
public void setRetryDelay(final RetryDelay retryDelay)
{
myRetryDelay = retryDelay;
}

@JsonProperty ("delay")
@JsonProperty("delay")
public RetryDelay getRetryDelay()
{
return myRetryDelay;
}

@JsonProperty ("retrySchedule")
@JsonProperty("retrySchedule")
public RetrySchedule getRetrySchedule()
{
return myRetrySchedule;
}

@JsonProperty ("retrySchedule")
@JsonProperty("retrySchedule")
public void setRetrySchedule(final RetrySchedule retrySchedule)
{
myRetrySchedule = retrySchedule;
}

private static long convertToMillis(final Long value, final String unit)
private static long convertToMillis(final Long value, final TimeUnit unit)
{
return switch (unit.toLowerCase(Locale.US))
{
case "milliseconds" -> value;
case "seconds" -> TimeUnit.SECONDS.toMillis(value);
case "minutes" -> TimeUnit.MINUTES.toMillis(value);
case "hours" -> TimeUnit.HOURS.toMillis(value);
case "days" -> TimeUnit.DAYS.toMillis(value);
default -> throw new IllegalArgumentException("Unsupported time unit: " + unit);
};
return unit.toMillis(value);
}

/**
Expand All @@ -97,67 +90,67 @@ public RetryDelay()

}

@JsonProperty ("start")
@JsonProperty("start")
private long myDelay = DEFAULT_DELAY_IN_MS;
@JsonProperty ("max")

@JsonProperty("max")
private long myMaxDelay = DEFAULT_MAX_DELAY_IN_MS;
@JsonProperty ("unit")
private String myUnit = DEFAULT_TIME_UNIT_IN_SECONDS;

@JsonProperty ("start")
@JsonProperty("unit")
private TimeUnit myTimeUnit = DEFAULT_TIME_UNIT_IN_SECONDS;

@JsonProperty("start")
public long getStartDelay()
{
return myDelay;
}

@JsonProperty ("start")
@JsonProperty("start")
public void setStartDelay(final Long delay)
{
if (delay != null)
{
long convertedDelay = convertToMillis(delay, myUnit);
long convertedDelay = convertToMillis(delay, myTimeUnit);
if (convertedDelay > myMaxDelay)
{
throw new IllegalArgumentException("Start delay cannot be greater than max delay.");
}
this.myDelay = convertToMillis(delay, myUnit);
this.myDelay = convertToMillis(delay, myTimeUnit);
}
}

@JsonProperty ("max")
@JsonProperty("max")
public long getMaxDelay()
{
return myMaxDelay;
}

@JsonProperty ("max")
@JsonProperty("max")
public void setMaxDelay(final Long maxDelay)
{
if (maxDelay != null)
{
long convertedMaxDelay = convertToMillis(maxDelay, myUnit);
long convertedMaxDelay = convertToMillis(maxDelay, myTimeUnit);
if (convertedMaxDelay < myDelay)
{
throw new IllegalArgumentException("Max delay cannot be less than start delay.");
}
this.myMaxDelay = convertToMillis(maxDelay, myUnit);
this.myMaxDelay = convertToMillis(maxDelay, myTimeUnit);
}
}

@JsonProperty ("unit")
public String getUnit()
@JsonProperty("unit")
public TimeUnit getUnit()
{
return myUnit;
return myTimeUnit;
}

@JsonProperty ("unit")
public void setUnit(final String unit)
@JsonProperty("unit")
public void setTimeUnit(final String unit)
{
if (unit != null && !unit.isBlank())
{
this.myUnit = unit;
this.myDelay = convertToMillis(TimeUnit.MILLISECONDS.toSeconds(this.myDelay), unit);
this.myMaxDelay = convertToMillis(TimeUnit.MILLISECONDS.toSeconds(this.myMaxDelay), unit);
myTimeUnit = TimeUnit.valueOf(unit.toUpperCase(Locale.US));
}
}
}
Expand All @@ -169,59 +162,58 @@ public RetrySchedule()

}

@JsonProperty ("initialDelay")
@JsonProperty("initialDelay")
private long myInitialDelay = DEFAULT_INITIAL_DELAY_IN_MS;
@JsonProperty ("fixedDelay")

@JsonProperty("fixedDelay")
private long myFixedDelay = DEFAULT_FIXED_DELAY_IN_MS;
@JsonProperty ("unit")
private String myUnit = DEFAULT_TIME_UNIT_IN_SECONDS;

@JsonProperty ("initialDelay")
@JsonProperty("unit")
private TimeUnit myTimeUnit = DEFAULT_TIME_UNIT_IN_SECONDS;

@JsonProperty("initialDelay")
public long getInitialDelay()
{
return myInitialDelay;
}

@JsonProperty ("initialDelay")
@JsonProperty("initialDelay")
public void setInitialDelay(final Long initialDelay)
{
if (initialDelay != null)
{
this.myInitialDelay = convertToMillis(initialDelay, myUnit);
this.myInitialDelay = convertToMillis(initialDelay, myTimeUnit);
}
}

@JsonProperty ("fixedDelay")
@JsonProperty("fixedDelay")
public long getFixedDelay()
{
return myFixedDelay;
}

@JsonProperty ("fixedDelay")
@JsonProperty("fixedDelay")
public void setFixedDelay(final Long fixedDelay)
{
if (fixedDelay != null)
{
this.myFixedDelay = convertToMillis(fixedDelay, myUnit);
this.myFixedDelay = convertToMillis(fixedDelay, myTimeUnit);
}
}

@JsonProperty ("unit")
public String getUnit()
@JsonProperty("unit")
public TimeUnit getUnit()
{
return myUnit;
return myTimeUnit;
}

@JsonProperty ("unit")
public void setUnit(final String unit)
@JsonProperty("unit")
public void setTimeUnit(final String unit)
{
if (unit != null && !unit.isBlank())
{
this.myUnit = unit;
this.myInitialDelay = convertToMillis(TimeUnit.MILLISECONDS.toSeconds(this.myInitialDelay), unit);
this.myFixedDelay = convertToMillis(TimeUnit.MILLISECONDS.toSeconds(this.myFixedDelay), unit);
myTimeUnit = TimeUnit.valueOf(unit.toUpperCase(Locale.US));
}

}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.dataformat.yaml.YAMLFactory;

import java.util.concurrent.TimeUnit;
import org.junit.Before;
import org.junit.Test;

Expand All @@ -39,7 +40,7 @@ public class TestConfig
{
private static final String DEFAULT_AGENT_FILE_NAME = "all_set.yml";
private static final String NOTHING_SET_AGENT_FILE_NAME = "nothing_set.yml";
private static final String TIME_UNIT_IN_SECONDS = "seconds";
private static final TimeUnit TIME_UNIT_IN_SECONDS = TimeUnit.SECONDS;
private static Config config;
private static DistributedNativeConnection nativeConnection;
private static DistributedJmxConnection distributedJmxConnection;
Expand Down

0 comments on commit 849adfb

Please sign in to comment.