Skip to content

Commit

Permalink
Added spotless to build
Browse files Browse the repository at this point in the history
Signed-off-by: rithin-pullela-aws <[email protected]>
  • Loading branch information
rithin-pullela-aws committed Jan 28, 2025
1 parent 5f7cbd9 commit 38edb42
Show file tree
Hide file tree
Showing 156 changed files with 5,217 additions and 4,299 deletions.
362 changes: 362 additions & 0 deletions .eclipseformat.xml

Large diffs are not rendered by default.

9 changes: 9 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -246,3 +246,12 @@ tasks.named('dependencyLicenses') {
thirdPartyAudit {
ignoreViolations('org.conscrypt.Platform')
}

spotless {
java {
removeUnusedImports()
importOrder 'java', 'javax', 'org', 'com'

eclipse().configFile rootProject.file('.eclipseformat.xml')
}
}
41 changes: 22 additions & 19 deletions src/javaRestTest/java/com/o19s/es/ltr/NodeSettingsIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,38 +16,41 @@

package com.o19s.es.ltr;

import static org.hamcrest.Matchers.allOf;
import static org.hamcrest.Matchers.greaterThan;
import static org.hamcrest.Matchers.greaterThanOrEqualTo;
import static org.hamcrest.Matchers.lessThan;

import java.io.IOException;

import org.apache.lucene.util.Accountable;
import org.opensearch.common.settings.Settings;
import org.opensearch.core.common.unit.ByteSizeUnit;
import org.opensearch.core.common.unit.ByteSizeValue;

import com.o19s.es.ltr.action.BaseIntegrationTest;
import com.o19s.es.ltr.feature.store.CompiledLtrModel;
import com.o19s.es.ltr.feature.store.MemStore;
import com.o19s.es.ltr.feature.store.index.CachedFeatureStore;
import com.o19s.es.ltr.feature.store.index.Caches;
import com.o19s.es.ltr.ranker.LtrRanker;
import org.apache.lucene.util.Accountable;
import org.opensearch.common.settings.Settings;
import org.opensearch.core.common.unit.ByteSizeUnit;
import org.opensearch.core.common.unit.ByteSizeValue;

import java.io.IOException;

import static org.hamcrest.Matchers.allOf;
import static org.hamcrest.Matchers.greaterThan;
import static org.hamcrest.Matchers.greaterThanOrEqualTo;
import static org.hamcrest.Matchers.lessThan;

public class NodeSettingsIT extends BaseIntegrationTest {
private final MemStore memStore = new MemStore();
private final int memSize = 1024;
private final int expireAfterRead = 100;
private final int expireAfterWrite = expireAfterRead*4;
private final int expireAfterWrite = expireAfterRead * 4;

@Override
protected Settings nodeSettings() {
Settings settings = super.nodeSettings();
return Settings.builder().put(settings)
.put(Caches.LTR_CACHE_MEM_SETTING.getKey(), memSize + "kb")
.put(Caches.LTR_CACHE_EXPIRE_AFTER_READ.getKey(), expireAfterRead + "ms")
.put(Caches.LTR_CACHE_EXPIRE_AFTER_WRITE.getKey(), expireAfterWrite + "ms")
.build();
return Settings
.builder()
.put(settings)
.put(Caches.LTR_CACHE_MEM_SETTING.getKey(), memSize + "kb")
.put(Caches.LTR_CACHE_EXPIRE_AFTER_READ.getKey(), expireAfterRead + "ms")
.put(Caches.LTR_CACHE_EXPIRE_AFTER_WRITE.getKey(), expireAfterWrite + "ms")
.build();
}

public void testCacheSettings() throws IOException, InterruptedException {
Expand All @@ -67,14 +70,14 @@ public void testCacheSettings() throws IOException, InterruptedException {
} while (totalAdded < maxMemSize);
assertThat(totalAdded, greaterThan(maxMemSize));
assertThat(caches.modelCache().weight(), greaterThan(0L));
Thread.sleep(expireAfterWrite*2);
Thread.sleep(expireAfterWrite * 2);
caches.modelCache().refresh();
assertEquals(0, caches.modelCache().weight());
cached.loadModel("test0");
// Second load for accessTime
cached.loadModel("test0");
assertThat(caches.modelCache().weight(), greaterThan(0L));
Thread.sleep(expireAfterRead*2);
Thread.sleep(expireAfterRead * 2);
caches.modelCache().refresh();
assertEquals(0, caches.modelCache().weight());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,23 @@

package com.o19s.es.ltr.action;

import com.o19s.es.ltr.action.AddFeaturesToSetAction.AddFeaturesToSetRequestBuilder;
import com.o19s.es.ltr.action.AddFeaturesToSetAction.AddFeaturesToSetResponse;
import com.o19s.es.ltr.feature.store.StoredFeature;
import com.o19s.es.ltr.feature.store.StoredFeatureSet;
import com.o19s.es.ltr.feature.store.index.IndexFeatureStore;
import org.opensearch.action.DocWriteResponse;
import static com.o19s.es.ltr.LtrTestUtils.randomFeature;
import static java.util.Arrays.asList;
import static org.hamcrest.CoreMatchers.containsString;
import static org.opensearch.ExceptionsHelper.unwrap;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.concurrent.ExecutionException;

import static com.o19s.es.ltr.LtrTestUtils.randomFeature;
import static java.util.Arrays.asList;
import static org.opensearch.ExceptionsHelper.unwrap;
import static org.hamcrest.CoreMatchers.containsString;
import org.opensearch.action.DocWriteResponse;

import com.o19s.es.ltr.action.AddFeaturesToSetAction.AddFeaturesToSetRequestBuilder;
import com.o19s.es.ltr.action.AddFeaturesToSetAction.AddFeaturesToSetResponse;
import com.o19s.es.ltr.feature.store.StoredFeature;
import com.o19s.es.ltr.feature.store.StoredFeatureSet;
import com.o19s.es.ltr.feature.store.index.IndexFeatureStore;

public class AddFeaturesToSetActionIT extends BaseIntegrationTest {
public void testAddToSetWithQuery() throws Exception {
Expand Down Expand Up @@ -100,7 +101,7 @@ public void testAddToSetWithList() throws Exception {
assertEquals(2, resp.getResponse().getVersion());
assertEquals(DocWriteResponse.Result.UPDATED, resp.getResponse().getResult());
set = getElement(StoredFeatureSet.class, StoredFeatureSet.TYPE, "new_feature_set");
assertEquals(features.size()+1, set.size());
assertEquals(features.size() + 1, set.size());
assertTrue(set.hasFeature("another_feature"));
}

Expand All @@ -109,8 +110,7 @@ public void testFailuresWhenEmpty() throws Exception {
builder.request().setFeatureSet("new_broken_set");
builder.request().setFeatureNameQuery("doesnotexist*");
builder.request().setStore(IndexFeatureStore.DEFAULT_STORE);
Throwable iae = unwrap(expectThrows(ExecutionException.class, () -> builder.execute().get()),
IllegalArgumentException.class);
Throwable iae = unwrap(expectThrows(ExecutionException.class, () -> builder.execute().get()), IllegalArgumentException.class);
assertNotNull(iae);
assertThat(iae.getMessage(), containsString("returned no features"));
}
Expand All @@ -127,14 +127,12 @@ public void testFailuresOnDuplicates() throws Exception {
assertEquals(DocWriteResponse.Result.CREATED, resp.getResponse().getResult());
assertEquals(1, resp.getResponse().getVersion());


AddFeaturesToSetRequestBuilder builder2= new AddFeaturesToSetRequestBuilder(client());
AddFeaturesToSetRequestBuilder builder2 = new AddFeaturesToSetRequestBuilder(client());
builder2.request().setFeatureSet("duplicated_set");
builder2.request().setFeatureNameQuery("duplicated");
builder2.request().setStore(IndexFeatureStore.DEFAULT_STORE);

Throwable iae = unwrap(expectThrows(ExecutionException.class, () -> builder2.execute().get()),
IllegalArgumentException.class);
Throwable iae = unwrap(expectThrows(ExecutionException.class, () -> builder2.execute().get()), IllegalArgumentException.class);
assertNotNull(iae);
assertThat(iae.getMessage(), containsString("defined twice in this set"));
}
Expand All @@ -143,7 +141,7 @@ public void testMergeWithQuery() throws Exception {
addElement(randomFeature("duplicated"));
addElement(randomFeature("new_feature"));

AddFeaturesToSetRequestBuilder builder= new AddFeaturesToSetRequestBuilder(client());
AddFeaturesToSetRequestBuilder builder = new AddFeaturesToSetRequestBuilder(client());
builder.request().setFeatureSet("merged_set");
builder.request().setFeatureNameQuery("duplicated*");
builder.request().setStore(IndexFeatureStore.DEFAULT_STORE);
Expand All @@ -153,7 +151,7 @@ public void testMergeWithQuery() throws Exception {
assertEquals(DocWriteResponse.Result.CREATED, resp.getResponse().getResult());
assertEquals(1, resp.getResponse().getVersion());

builder= new AddFeaturesToSetRequestBuilder(client());
builder = new AddFeaturesToSetRequestBuilder(client());
builder.request().setFeatureSet("merged_set");
builder.request().setFeatureNameQuery("*");
builder.request().setStore(IndexFeatureStore.DEFAULT_STORE);
Expand All @@ -176,7 +174,7 @@ public void testMergeWithList() throws Exception {
features.add(feat);
}

AddFeaturesToSetRequestBuilder builder= new AddFeaturesToSetRequestBuilder(client());
AddFeaturesToSetRequestBuilder builder = new AddFeaturesToSetRequestBuilder(client());
builder.request().setFeatureSet("new_feature_set");
builder.request().setFeatures(features);
builder.request().setMerge(true);
Expand All @@ -191,7 +189,7 @@ public void testMergeWithList() throws Exception {
assertEquals(features.size(), set.size());
assertTrue(features.stream().map(StoredFeature::name).allMatch(set::hasFeature));

builder= new AddFeaturesToSetRequestBuilder(client());
builder = new AddFeaturesToSetRequestBuilder(client());
builder.request().setFeatureSet("new_feature_set");
builder.request().setFeatures(asList(randomFeature("another_feature"), randomFeature("feature0")));
builder.request().setMerge(true);
Expand All @@ -200,7 +198,7 @@ public void testMergeWithList() throws Exception {
assertEquals(2, resp.getResponse().getVersion());
assertEquals(DocWriteResponse.Result.UPDATED, resp.getResponse().getResult());
set = getElement(StoredFeatureSet.class, StoredFeatureSet.TYPE, "new_feature_set");
assertEquals(features.size()+1, set.size());
assertEquals(features.size() + 1, set.size());
assertTrue(set.hasFeature("another_feature"));
assertEquals(0, set.featureOrdinal("feature0"));
}
Expand Down
Loading

0 comments on commit 38edb42

Please sign in to comment.