Skip to content
This repository was archived by the owner on Apr 15, 2026. It is now read-only.

Dvurechensky-Test-Tasks/NET_Junior_Ads_Test_Task

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

253 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

✨Dvurechensky✨

AdPlatformService - Junior .NET Test Task πŸ“„

🌐 Language: πŸ‡·πŸ‡Ί Russian | βœ… πŸ‡ΊπŸ‡Έ English (current)

AdPlatformService is a high-performance in-memory web service for storing and searching advertising platforms by location.

πŸ“„ Task documentation is also available in PDF: TASK.NET.pdf
πŸ“„ Test input file: test_input_data.txt

⭐ Table of Contents


πŸš€ Run

Start

dotnet run --project AdRegionService

Debug

πŸ‘‰ API: http://localhost:5411 πŸ‘‰ Swagger UI: http://localhost:5411/swagger

Release

πŸ‘‰ API: http://localhost:5411 πŸ‘‰ Swagger UI: http://localhost:5411/swagger


API

Show API details
POST /api/load
Content-Type: multipart/form-data

[email protected]
{
	"message": "Data loaded",
	"loaded": 123,
	"skipped": 5
}
GET /api/search?location=/ru/svrd
[
	{ "name": "Cool Ads", "locations": ["/ru/svrd"] },
	{
		"name": "Revdinsky Worker",
		"locations": ["/ru/svrd/revda", "/ru/svrd/pervik"]
	}
]

✨ Features

  • πŸ“‚ Load advertising platforms from file (Stream)

  • ⚑ In-memory storage using immutable collections

  • πŸ“Š Load statistics (loaded / skipped)

  • πŸ” Hierarchical location search:

    • /loc1 matches all platforms under this level
    • /loc1/loc2 also includes /loc1
  • πŸ›‘ Error handling:

    • OperationCanceledException
    • OutOfMemoryException
    • General errors are logged, state remains consistent

πŸ”Ή Core Functionality

1. Loading platforms from file

Method:

LoadFromStreamAsync(Stream stream, CancellationToken cancellationToken = default)

Key Features

  • βœ… Accepts Stream (supports files and network sources)

  • βœ… Ignores invalid lines:

    • empty lines
    • missing :
    • empty platform name
    • no valid locations
  • βœ… Location indexing Stored in:

ImmutableDictionary<string, ImmutableHashSet<AdPlatform>>
  • βœ… Load statistics (LoadStats)
  • βœ… Progress logging every 100,000 lines
  • βœ… Error resilience:
    • keeps previous state on failure
    • logs all exceptions

Example file format

Yandex.Direct:/ru
Revdinsky Worker:/ru/svrd/revda,/ru/svrd/pervik
Ural Moscow Newspaper:/ru/msk,/ru/permobl,/ru/chelobl
Cool Ads:/ru/svrd

2. Search by location

  • βœ… Method: Search(string location)
  • βœ… Uses indexed lookup (no full scan)
  • βœ… Supports hierarchical matching
  • βœ… Returns IEnumerable<AdPlatform>
  • βœ… Thread-safe
  • ⚑ Efficient up to:
    • 1–2 million entries
    • 100–500 MB data

For >10M entries β†’ consider external storage (PostgreSQL, full-text search, etc.)


πŸ”Ή Technical Approach

Immutable Collections

  • ImmutableArray
  • ImmutableDictionary
  • ImmutableHashSet

➑️ Thread-safe without locks


Hierarchical Index

Search /a/b/c β†’ checks:

  • /a
  • /a/b
  • /a/b/c

Logging

  • ILogger
  • Progress logging
  • Error tracking
  • Ready for integration (Seq, Kibana, etc.)

Fault Tolerance

  • Invalid data is skipped
  • State is preserved on failure
  • Search never throws exceptions

Set-based Search

  • Uses HashSet<AdPlatform>
  • Removes duplicates automatically
  • Returns lightweight enumerable

πŸ”Ή Advantages

  • ⚑ High performance (1–2M entries)
  • πŸ›‘ Robust error handling
  • πŸ”— Easy REST integration
  • 🧡 Thread-safe architecture

πŸ”Ή Testing

  • xUnit tests

  • Covers:

    • loading
    • search
    • edge cases
  • Run:

dotnet test

πŸ›  CI/CD

  • Docker build on push to main
  • Publish to GitHub Container Registry
  • dotnet build + dotnet test

πŸ”Ή Docker

Generate certificate

openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout key.pem -out cert.pem -subj "/CN=localhost"

Run container

docker-compose up --build

Access


Pull image

docker pull ghcr.io/dvurechensky/net_junior_ads_test_task/adservice:latest

Run

docker run -it --rm -p 5411:5411 ghcr.io/dvurechensky/net_junior_ads_test_task/adservice:latest

✨Dvurechensky✨