Skip to content

Commit 1a87f98

Browse files
Revert "Removing legacy remote-settings client (#7186)" (#7255)
This reverts commit 64aaa9b.
1 parent c7c5854 commit 1a87f98

File tree

21 files changed

+1629
-60
lines changed

21 files changed

+1629
-60
lines changed

CHANGELOG.md

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,6 @@
66
* The `MetricsHandler` interface now requires two additional methods: `record_database_load()` and `record_database_migration()`
77
* In Kotlin expose `GleanMetrics.Pings.nimbusTargetingContext` as `Nimbus.Pings.nimbusTargetingContext` for downstream tests. ([#14542](https://github.com/mozilla/experimenter/issues/14542))
88

9-
### Remote-Settings
10-
* Removed old remote-settings client code that is no longer used.
11-
* Renaming `RemoteSettingsConfig2` to `RemoteSettingsConfig`, which will require client updates.
12-
139
[Full Changelog](In progress)
1410

1511
# v149.0 (_2026-02-23_)

components/nimbus/android/src/test/java/org/mozilla/experiments/nimbus/NimbusBuilderTest.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ package org.mozilla.experiments.nimbus
77
import android.content.Context
88
import androidx.test.core.app.ApplicationProvider
99
import kotlinx.coroutines.Job
10-
import mozilla.appservices.remotesettings.RemoteSettingsConfig
10+
import mozilla.appservices.remotesettings.RemoteSettingsConfig2
1111
import mozilla.appservices.remotesettings.RemoteSettingsService
1212
import org.junit.Assert.assertEquals
1313
import org.junit.Assert.assertFalse
@@ -35,7 +35,7 @@ class NimbusBuilderTest {
3535
}.build(
3636
appInfo,
3737
NimbusServerSettings(
38-
rsService = RemoteSettingsService(storageDir = "dummy", config = RemoteSettingsConfig()),
38+
rsService = RemoteSettingsService(storageDir = "dummy", config = RemoteSettingsConfig2()),
3939
collectionName = "nimbus-preview",
4040
),
4141
) as DummyNimbus

components/nimbus/tests/common.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,6 @@
33
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
44
#![cfg(feature = "rkv-safe-mode")]
55

6-
use remote_settings::{RemoteSettingsConfig, RemoteSettingsContext, RemoteSettingsService};
7-
use rkv::StoreOptions;
8-
96
// utilities shared between tests
107

118
use nimbus::error::{Result, debug};
@@ -16,6 +13,8 @@ use nimbus::metrics::{
1613
use nimbus::stateful::client::NimbusServerSettings;
1714
use nimbus::stateful::persistence::{Database, SingleStore};
1815
use nimbus::{AppContext, NimbusClient, RemoteSettingsServer};
16+
use remote_settings::{RemoteSettingsConfig2, RemoteSettingsContext, RemoteSettingsService};
17+
use rkv::StoreOptions;
1918
use std::{path::Path, sync::Arc};
2019

2120
pub struct NoopMetricsHandler;
@@ -94,7 +93,7 @@ fn new_test_client_internal(
9493
..Default::default()
9594
};
9695

97-
let config = RemoteSettingsConfig {
96+
let config = RemoteSettingsConfig2 {
9897
server: Some(RemoteSettingsServer::Custom {
9998
url: url.as_str().to_string(),
10099
}),

components/nimbus/tests/test_fs_client.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,13 @@ mod common;
99

1010
use std::path::PathBuf;
1111
use std::sync::Arc;
12+
1213
use url::Url;
1314

1415
use nimbus::error::Result;
1516
use nimbus::stateful::client::NimbusServerSettings;
1617
use nimbus::{NimbusClient, RemoteSettingsServer};
17-
use remote_settings::{RemoteSettingsConfig, RemoteSettingsContext, RemoteSettingsService};
18+
use remote_settings::{RemoteSettingsConfig2, RemoteSettingsContext, RemoteSettingsService};
1819

1920
use crate::common::NoopMetricsHandler;
2021

@@ -29,7 +30,7 @@ fn test_simple() -> Result<()> {
2930

3031
let url = Url::from_file_path(dir).expect("experiments dir should exist");
3132

32-
let config = RemoteSettingsConfig {
33+
let config = RemoteSettingsConfig2 {
3334
server: Some(RemoteSettingsServer::Custom {
3435
url: url.as_str().to_string(),
3536
}),

components/relay/src/rs.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -298,11 +298,11 @@ impl RelayRemoteSettingsClient {
298298
#[cfg(test)]
299299
mod tests {
300300
use super::*;
301-
use remote_settings::{RemoteSettingsConfig, RemoteSettingsServer};
301+
use remote_settings::{RemoteSettingsConfig2, RemoteSettingsServer};
302302

303303
// Helper to create a RemoteSettingsService for testing
304304
fn create_test_remote_settings_service() -> Arc<RemoteSettingsService> {
305-
let config = RemoteSettingsConfig {
305+
let config = RemoteSettingsConfig2 {
306306
server: Some(RemoteSettingsServer::Custom {
307307
url: "http://localhost".to_string(),
308308
}),
Lines changed: 168 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,168 @@
1+
/* This Source Code Form is subject to the terms of the Mozilla Public
2+
* License, v. 2.0. If a copy of the MPL was not distributed with this
3+
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
4+
5+
package org.mozilla.appservices.remotesettings
6+
7+
import mozilla.appservices.httpconfig.RustHttpConfig
8+
import mozilla.appservices.remotesettings.RemoteSettings
9+
import mozilla.appservices.remotesettings.RemoteSettingsConfig
10+
import mozilla.components.concept.fetch.Client
11+
import mozilla.components.concept.fetch.Headers
12+
import mozilla.components.concept.fetch.MutableHeaders
13+
import mozilla.components.concept.fetch.Request
14+
import mozilla.components.concept.fetch.Response
15+
import org.junit.Assert.assertEquals
16+
import org.junit.Assert.assertTrue
17+
import org.junit.Before
18+
import org.junit.Rule
19+
import org.junit.Test
20+
import org.junit.rules.TemporaryFolder
21+
import org.junit.runner.RunWith
22+
import org.robolectric.RobolectricTestRunner
23+
import java.io.File
24+
import java.io.InputStream
25+
26+
@RunWith(RobolectricTestRunner::class)
27+
class RemoteSettingsTest {
28+
29+
@Rule @JvmField
30+
val tempDir = TemporaryFolder()
31+
32+
private var fakeUrl = ""
33+
private var fakeStatus = 200
34+
private var fakeHeaders: Headers = MutableHeaders("etag" to "\"1000\"")
35+
private var fakeBodyStream = "".byteInputStream()
36+
private var fakeContentType = ""
37+
private var fakeBody = Response.Body(fakeBodyStream, fakeContentType)
38+
private var doFetch: (Request) -> Response = {
39+
Response(fakeUrl, fakeStatus, fakeHeaders, fakeBody)
40+
}
41+
42+
@Before
43+
fun setup() {
44+
RustHttpConfig.setClient(
45+
lazyOf(object : Client() {
46+
override fun fetch(request: Request): Response = doFetch(request)
47+
}),
48+
)
49+
}
50+
51+
@Test
52+
fun `test setting up, fetching records, and attachment downloading`() {
53+
val config = RemoteSettingsConfig(
54+
serverUrl = "http://localhost:8888",
55+
bucketName = "the-bucket",
56+
collectionName = "the-collection",
57+
)
58+
59+
// Setup the client
60+
val client = RemoteSettings(config)
61+
62+
// Fetch the records
63+
setupRecordResponse(config, responseBodyStream = recordJson.byteInputStream())
64+
val response = client.getRecords()
65+
val records = response.records
66+
assertEquals(records[0].fields.getString("title"), recordTitle)
67+
68+
// Download an attachment
69+
val attachmentLocation = records[0].attachment!!.location
70+
val localAttachmentPath = "${tempDir.root}/path.jpg"
71+
setupAttachmentResponses(config, attachmentLocation)
72+
client.downloadAttachmentToPath(attachmentLocation, localAttachmentPath)
73+
val downloadedFile = File(localAttachmentPath)
74+
assertTrue(downloadedFile.exists())
75+
assertEquals(csv, downloadedFile.readText())
76+
}
77+
78+
private fun setupAttachmentResponses(
79+
config: RemoteSettingsConfig,
80+
attachmentLocation: String,
81+
) {
82+
val topUrl = config.serverUrl
83+
val attachmentUrl = "${config.serverUrl}/attachments/$attachmentLocation"
84+
doFetch = { req ->
85+
when (req.url) {
86+
"$topUrl/v1/" -> {
87+
Response(
88+
url = req.url,
89+
status = 200,
90+
headers = fakeHeaders,
91+
body = Response.Body(
92+
stream = attachmentsInfoJson(topUrl!!).byteInputStream(),
93+
null,
94+
),
95+
)
96+
}
97+
attachmentUrl -> {
98+
Response(
99+
url = attachmentUrl,
100+
status = 200,
101+
headers = fakeHeaders,
102+
body = Response.Body(
103+
stream = csv.byteInputStream(),
104+
null,
105+
),
106+
)
107+
}
108+
else -> error("unexpected url")
109+
}
110+
}
111+
}
112+
private fun setupRecordResponse(
113+
config: RemoteSettingsConfig,
114+
responseBodyStream: InputStream = recordJson.byteInputStream(),
115+
) {
116+
fakeUrl = "${config.serverUrl}/v1/buckets/${config.bucketName}/collections/${config.collectionName}/records"
117+
fakeBody = Response.Body(responseBodyStream, null)
118+
}
119+
120+
private fun attachmentsInfoJson(baseUrl: String) = """
121+
{
122+
"capabilities": {
123+
"admin": {
124+
"description": "Serves the admin console.",
125+
"url": "https://github.com/Kinto/kinto-admin/",
126+
"version": "2.0.0"
127+
},
128+
"attachments": {
129+
"description": "Add file attachments to records",
130+
"url": "https://github.com/Kinto/kinto-attachment/",
131+
"version": "6.3.1",
132+
"base_url": "$baseUrl/attachments/"
133+
}
134+
}
135+
}
136+
""".trimIndent()
137+
138+
private val recordTitle = "with-txt-attachment"
139+
private val recordJson = """
140+
{
141+
"data": [
142+
{
143+
"title": "$recordTitle",
144+
"content": "content",
145+
"attachment": {
146+
"filename": "text-attachment.csv",
147+
"location": "the-bucket/the-collection/d3a5eccc-f0ca-42c3-b0bb-c0d4408c21c9.jpg",
148+
"hash": "2cbd593f3fd5f1585f92265433a6696a863bc98726f03e7222135ff0d8e83543",
149+
"mimetype": "text/csv",
150+
"size": 1374325
151+
},
152+
"schema": 1677694447771,
153+
"id": "7403c6f9-79be-4e0c-a37a-8f2b5bd7ad58",
154+
"last_modified": 1677694455368
155+
}
156+
]
157+
}
158+
""".trimIndent()
159+
160+
private val csv = """
161+
John,Doe,120 jefferson st.,Riverside, NJ, 08075
162+
Jack,McGinnis,220 hobo Av.,Phila, PA,09119
163+
"John ""Da Man""${'"'},Repici,120 Jefferson St.,Riverside, NJ,08075
164+
Stephen,Tyler,"7452 Terrace ""At the Plaza"" road",SomeTown,SD, 91234
165+
,Blankman,,SomeTown, SD, 00298
166+
"Joan ""the bone"", Anne",Jet,"9th, at Terrace plc",Desert City,CO,00123
167+
""".trimIndent()
168+
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Robolectric doesn't support SDK 36 yet, so pin to 35
2+
sdk=35

0 commit comments

Comments
 (0)